优化技巧:
将字符串映射成数字,方便存储也加快比较速度(配合map的find函数)
#include #include #include #include #include #include #include #include using namespace std; unordered_maparticle[10001];//(没啥用了) article[i][j]代表第i行j列的字符串(所映射的数字) unordered_mapword;//保存一下将字符串映射成数字的结果 int idx; int n,m; int have_ans=0; int a[10001][11]; bool solve(int i,int j); struct nodes { int x,y; bool operator < (const nodes &temp) const { // if(x==temp.x&&y==temp.y) return false; // if(x==temp.x) // { // return y t;//把同一列下的两个元素储存起来 for(int r1=1;r1<=n;r1++) { nodes p={a[r1][c1],a[r1][c2]}; //printf("%d -%d,%d %d-%d,%dn",a[r1][c1],r1,c1,a[r1][c2],r1,c2); if(t.find(p)!=t.end()) { have_ans=1; printf("NOn"); printf("%d %dn%d %dn",t[p],r1,c1,c2); return; } t[p]=r1; } t.clear(); } } } void init() { have_ans=0; idx=0; } int main() { //freopen("uva1592.txt","r",stdin); //freopen("uva1592-out.txt","w",stdout); while(scanf("%d%d",&n,&m)!=EOF) { getchar(); init(); for(int i=1;i<=n;i++) { string str; getline(cin,str); str.push_back(','); operate_str(str,i); } solve(); if(have_ans) { //printf("NOn"); //printf("%d %dn%d %dn",ans.r1,ans.r2,ans.c1,ans.c2); } else { printf("YESn"); } } return 0; }
上一篇 7.19 Web前端-css特殊选择器
下一篇 【无标题】
版权所有 (c)2021-2022 MSHXW.COM
ICP备案号:晋ICP备2021003244-6号