欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

Uva1592Database

时间:2023-06-05

原题:

思路:用一个IDcache去给所有字符串分配ID,再利用pair构成二元组。维护左端点c1,枚举右端点c2,同时遍历row从上到下扫分配的id库。查询第row行pair(c1,c2)是否存在即可。

代码:

#include#include#include#include#include//集合#include //映射#include//向量#include//pair#define DEBUGusing namespace std;map IDcache;//记录IDmap,int> Binary_pair;//记录二元组所在rowint cnt=0;int ID(string s)//分配ID{ if(IDcache.count(s)) { return IDcache[s]; } else { return IDcache[s]=cnt++; }}int main(void){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,m; while(cin>>n>>m) { IDcache.clear(); Binary_pair.clear(); vector> dict(n,vector(m));//存放ID string s; cnt=0; cin.get();//消去换行 for(int i=0;i>cur; dict[i][j]=ID(cur); } } #ifndef DEBUG//调试语句 for(int i=0;i1) { for(int c1=0;c1 temp(dict[row][c1],dict[row][c2]); if(Binary_pair.count(temp))//并非Peter范式 { cout<<"NO"<

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。