原题:
思路:用一个IDcache去给所有字符串分配ID,再利用pair构成二元组。维护左端点c1,枚举右端点c2,同时遍历row从上到下扫分配的id库。查询第row行pair(c1,c2)是否存在即可。
代码:
#include #include #include #include #include//集合 #include//映射 #include//向量 #include//pair #define DEBUG using namespace std; map IDcache;//记录ID map,int> Binary_pair;//记录二元组所在row int 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"<
上一篇 python使用numpy中的np.add函数和np.subtract函数对二维numpy数组进行相加或者相减(Adding And Subtracting Matrices)
下一篇 贪心 (推公式)
版权所有 (c)2021-2022 MSHXW.COM
ICP备案号:晋ICP备2021003244-6号