UVa1592 数据库(摘)
2016-04-11 20:23
288 查看
输入一个n行m列的数据库(1<=n<=10000,1<=m<=10),是否存在两个不同行r1,r2和两个不同列c1,c2,使得这两行和这两行相同(即(r1,c1)和(r2,c1)相同,
(r1,c2)和(r2,c2)相同)。例如,对于如图所示的数据库,第2、3行和第2、3列满足要求
Input
Input contains several datasets. The first line of each dataset contains two integer numbersn and m (1
n
10000, 1
m
10), the number of rows and columns in the table. The following n lines contain table rows. Each row hasm column values separated by commas. Column values consist of ASCII characters from space (ASCII code 32) to tilde (ASCII code 126) with the exception of comma (ASCII code 44). Values are not empty and have no leading and trailing spaces. Each row has at most 80 characters (including separating commas).
Output
For each dataset, if the table is in PNF write to the output file a single word ``YES" (without quotes). If the table is not in PNF, then write three lines. On the first line write a single word ``NO" (without quotes). On the second line write two integer row numbers r1 andr2 (1
r1,r2
n,r1
r2), on the third line write two integer column numbers c1 andc2 (1
c1,c2
m,c1
c2), so that values in columnsc1 andc2 are the same in rowsr1 andr2.
Sample input
Sample output
(r1,c2)和(r2,c2)相同)。例如,对于如图所示的数据库,第2、3行和第2、3列满足要求
How to compete in AM ICPC | Peter | peter@neerc.ifmo.ru |
How to win in AM ICPC | Michael | michael@neerc.ifmo.ru |
Notes from AM ICPC champion | Michael | michael@neerc.ifmo.ru |
Input contains several datasets. The first line of each dataset contains two integer numbersn and m (1
n
10000, 1
m
10), the number of rows and columns in the table. The following n lines contain table rows. Each row hasm column values separated by commas. Column values consist of ASCII characters from space (ASCII code 32) to tilde (ASCII code 126) with the exception of comma (ASCII code 44). Values are not empty and have no leading and trailing spaces. Each row has at most 80 characters (including separating commas).
Output
For each dataset, if the table is in PNF write to the output file a single word ``YES" (without quotes). If the table is not in PNF, then write three lines. On the first line write a single word ``NO" (without quotes). On the second line write two integer row numbers r1 andr2 (1
r1,r2
n,r1
r2), on the third line write two integer column numbers c1 andc2 (1
c1,c2
m,c1
c2), so that values in columnsc1 andc2 are the same in rowsr1 andr2.
Sample input
3 3 How to compete in ACM ICPC,Peter,peter@neerc.ifmo.ru How to win ACM ICPC,Michael,michael@neerc.ifmo.ru Notes from ACM ICPC champion,Michael,michael@neerc.ifmo.ru 2 3 1,Peter,peter@neerc.ifmo.ru 2,Michael,michael@neerc.ifmo.ru
Sample output
NO 2 3 2 3 YES
#include<iostream> #include<cstdio> #include<map> #include<string> #include<vector> using namespace std; const int ROW = 10000 + 10; const int COL = 10 + 5; int n,m; map<string, int> IDcache; vector<string> Strcache; vector<int> Text[ROW]; //处理后的文本,每个字符串都对应一个编号 struct node { int x,y; node(int x, int y):x(x),y(y) { } bool operator < (const node& r) const{ //重载'<' return x<r.x || x==r.x&&y<r.y; } }; map<node,int> data; int f(string str) { if(IDcache.count(str)) return IDcache[str]; Strcache.push_back(str); return IDcache[str] = Strcache.size()-1; } void read() { string str; char ch = getchar(); for(int i=0;i<n;i++) { for(;;) { ch = getchar(); if(ch=='\n'||ch=='\r') { if(!str.empty()) Text[i].push_back(f(str)); str.clear(); break; } if(ch!=',') str += ch; else { Text[i].push_back(f(str)); str.clear(); } } } } void solve() { int x,y,c1,c2; for(c1=0;c1<m;c1++) { for(c2=c1+1;c2<m;c2++) { data.clear(); for(int r=0;r<n;r++) { x = Text[r][c1]; y = Text[r][c2]; node p(x,y); if(!data.count(p)) data[p] = r; else{ cout<<"NO"<<endl; cout<<data[p]+1<<" "<<r+1<<endl<<c1+1<<" "<<c2+1<<endl; return; } } } } cout<<"YES"<<endl; } int main() { while(cin>>n>>m) { read(); solve(); for(int i=0;i<n;i++) Text[i].clear(); IDcache.clear(); Strcache.clear(); } //system("pause"); return 0; }
相关文章推荐
- 数据库设计 Step by Step (6) —— 提取业务规则
- MySQL表字段的创建、删除、修改操作
- MySql中having字句对组记录进行筛选使用说明
- 查找未公开的oracle初始化参数
- 不用游标遍历数据库执行脚本
- 数据库连接池原理(转载)
- Ehcache和Memcached比较分析
- 解压版mysql配置问题(环境变量和注册表)
- Oracle VM + centos7.1+openstack kilo 多结点安装教程---keystone的安装(1)
- ehcache memcache redis 三大缓存男高音
- mysql 更改root密码的SQL
- sqlserver插入数据后自动返回自增编号方法
- mysql数据库中find_in_set()和in()用法区别
- plsql学习的心得
- JSP连接MySQL数据库和sql server数据库
- Mysql-5.6.x多实例配置
- 第9天-mysql创建高级联结
- Python 操作Mariadb数据库 +Linux
- nosql数据库不提供事务
- Spring Boot使用redis做数据缓存