栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

UVA 1592 DataBase

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

UVA 1592 DataBase

优化技巧:

将字符串映射成数字,方便存储也加快比较速度(配合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;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1019224.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号