输入一个n行m列的数据库(1<=n<=10000,1<=m<=10),是否存在两个不同行r1,r2和两个不同列c1,c2,使得这两行和这两行相同(即(r1,c1)和(r2,c1)相同,

(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

Input contains several datasets. The first line of each dataset contains two integer numbersn and m (1n10000, 1m10), 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 (1r1,r2n,r1r2), on the third line write two integer column numbers c1 andc2 (1c1,c2m,c1c2), 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 = + ;
const int COL = + ;
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()-;
} void read()
{
string str;
char ch = getchar();
for(int i=;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=;c1<m;c1++)
{
for(c2=c1+;c2<m;c2++)
{
data.clear();
for(int r=;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]+<<" "<<r+<<endl<<c1+<<" "<<c2+<<endl;
return;
}
}
}
}
cout<<"YES"<<endl;
} int main()
{
while(cin>>n>>m)
{
read();
solve();
for(int i=;i<n;i++) Text[i].clear();
IDcache.clear(); Strcache.clear();
}
//system("pause");
return ;
}

UVa1592 数据库(摘)的更多相关文章

  1. JSP应用开发 -------- 电纸书(未完待续)

    http://www.educity.cn/jiaocheng/j9415.html JSP程序员常用的技术   第1章 JSP及其相关技术导航 [本章专家知识导学] JSP是一种编程语言,也是一种动 ...

  2. 【摘】Mysql备份还原数据库之mysqldump实例及参数详细说明

    原文http://www.cnblogs.com/xuejie/archive/2013/01/11/2856911.html   我们在运营项目的过程中肯定会遇到备份数据库,还原数据库的情况,我们一 ...

  3. C#-VS SQLServer数据库编程-摘

    ado.net 通用类对象.在本地内存暂存数据 托管类对象.让本地通用类对象连接数据库,让本地通用类对象和数据库同步 连接数据库 new connection(connectstring) comma ...

  4. 摘:用ADO操作数据库的方法步骤

    用ADO操作数据库的方法步骤 ADO接口简介 ADO库包含三个基本接口:_ConnectionPtr接口._CommandPtr接口和_RecordsetPtr接口. _ConnectionPtr接口 ...

  5. 摘:VC开发数据库基础之ADO篇

    一.ADO简介ADO(ActiveX Data Object)是Microsoft数据库应用程序开发的新接口,是建立在OLE DB之上的高层数据库访问技术,请不必为此担心,即使你对OLE DB,COM ...

  6. 摘:C++:用ADO操作数据库的方法步骤

      ADO接口简介 ADO库包含三个基本接口:_ConnectionPtr接口._CommandPtr接口和_RecordsetPtr接口. _ConnectionPtr接口返回一个记录集或一个空指针 ...

  7. 算法习题---5.9数据库(Uva1592)

    一:题目 对数据库中数据进行检测,是否出现数据冗余现象.即是否某一列出现两个及以上数据重复 如上图中,第二列中第2,3行数据重复,所以我们判断为数据冗余.因为他可以分解为下面两张表 (一)样例输入 H ...

  8. 对象和数据库的天然阻抗 转摘于:http://www.jdon.com/mda/oo-reltaion2.html

    在“面向对象建模与数据库建模两种分析设计方法的比较”一文中我们比较了在对需求分析时两种方法的不同,所谓数据库建模分析,就是项目一开始就根据需求建立数据库模型,如数据表结构和字段等,这种错误现象大量普遍 ...

  9. PL/SQL Developer连接本地Oracle 11g 64位数据库

    转摘:http://www.cnblogs.com/ymj126/p/3712727.html 用于学习,笔记,以备后用. 1.登录PL/SQL Developer 这里省略Oracle数据库和PL/ ...

随机推荐

  1. Cogs 12 运输问题2 (有上下界网络流)

    #include <cstdlib> #include <algorithm> #include <cstring> #include <iostream&g ...

  2. C++Primer笔记(2)

    大型程序一般都是分为多个模块,由多人协作来进行开发的,其中还不可避免的会用到库.而各个模块代码以及库中会定义大量变量,而大量变量的命名,不可避免的会遇见“重名”的问题.“重名”的情况我们称之为命名空间 ...

  3. Remove掉Request.QueryString

    好久上博客来了,最近有点忙,有点懒. 今天在解决一个Request.QueryString 传值的问题上遇到了,当不是第一次加载时需要把Request.QueryString的值赋值为null,刚开始 ...

  4. ViewDragHelper的使用

    一.ViewDragHelper的原理 是一个能够自用移动ViewGroup内部View的控件. 通过获取ViewGroup的点击事件,之后通过Scroller滑动来进行对ViewGroup内部控件的 ...

  5. nignx开启expires后相关资源不显示的问题

    expires可以指定浏览器缓存,加快浏览速度 但是开启expires必须先指定root server中原来指定 location / { root D:/WWW; index index.html ...

  6. (转)css中通常会用到浮动与清除,也是一个必须掌握的知识点,概念性的东西不多说,下面举几个例子,来说明它的用法:1.文字环绕效果 2.多个div并排显示 3.清除浮动(默认显示)

    一.文字环绕效果: html代码如下: 1 <body> 2 3 <style type="text/css"> 4 #big img {float: le ...

  7. Oracle 10.2数据库管理员指南-27章

    27使用调度程序 Oracle Database provides database job capabilities through Oracle Scheduler (the Scheduler) ...

  8. 畅通工程续--hdu1874

    畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. 论如何进CSDN博客排名前500

    http://www.jtahstu.com/blog/post-71.html 目前该方法并不适用于博客园,显然写博客园的程序员智商要高些.

  10. ASP.NET MVC DefaultModelBinder

    转载自 Leo‘s Blog 看到很多ASP.NET MVC项目还在从request.querystring或者formContext里面获取数据,这实在是非常落后的做法.也有的项目建了大量的自定义的 ...