zoukankan      html  css  js  c++  java
  • 【例题5-9 UVA

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    枚举不同的列是哪两个列,然后枚举行。 把那一行的这两列的字符接在一起,然后用map判重。 为了防止逐个比较字符。 可以一开始先把字符串转换成一个整数。 这样,每一行就是一个整数的二元组(x,y)了; 用map,int>判重也可以; 或者把它转成long long的数字->x乘一个10W把Y加上去 后者更好。 **关同步的时候,getchar()不能用,可以用cin.get()代替**

    【代码】

    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 1e4;
    const int M = 10;
    
    map <string, int > dic;
    map <long long, int> mmap;
    int n, m;
    string S[N+10][M+10];
    int a[N + 10][M + 10];
    
    bool ok()
    {
    	int tot = 0;
    	dic.clear();
    	for (int i = 1;i <= n;i++)
    		for (int j = 1; j <= m; j++)
    		{
    			if (dic[S[i][j]] == 0) dic[S[i][j]] = ++tot;
    			a[i][j] = dic[S[i][j]];
    		}
    	for (int j = 1; j <= m; j++)
    		for (int k = j + 1; k <= m; k++)
    		{
    			mmap.clear();
    			for (int i = 1; i <= n; i++)
    			{
    				long long ts = 1LL * a[i][j] * 100000 + a[i][k];
    				if (mmap.find(ts) != mmap.end())
    				{
    					cout << "NO" << endl;
    					cout << mmap[ts] << ' ' << i << endl;
    					cout << j << ' ' << k << endl;
    					return true;
    				}
    				else
    					mmap[ts] = i;
    			}
    		}
    	return false;
    }
    
    int main()
    {
    	//freopen("F:\rush.txt", "r", stdin);
    	ios::sync_with_stdio(0), cin.tie(0);
    	while (cin >> n >> m)
    	{
    		cin.get();
    		for (int i = 1;i <=n;i++)
    			{
    				string ss;
    				getline(cin, ss);
    				int len = ss.size(),x = 0;
    				for (int j = 1; j <= m; j++,x++)
    				{
    					string s = "";
    					while (x <= len - 1 && ss[x] != ',')
    					{
    						s += ss[x];
    						x++;
    					}
    					S[i][j] = s;
    				}
    			}
    		if (!ok()) cout << "YES" << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    去除字符串中的重复字符
    .net生成的类,跨工程调用显示注释
    Flex 页面空白或Error #2032: 流错误处理办法
    读取点阵字库
    SQL多表联合查询(Access数据库表)
    MSComm不能触发MSComm1_OnComm()事件原因之一
    一个小时内学习SQLite数据库(转)
    人生无悔
    学习之道
    挺经
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7662420.html
Copyright © 2011-2022 走看看