输入一个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. 用Java来比较JavaScript的一些特性

    由于是从java做到JavaScript,所以对强弱语言类型,还是比较敏感的.JavaScript是弱语言,只严格区分数据和指令.简单描述下自己对两者之间的一些区别吧. 1.JavaScript变量的 ...

  2. mysql索引之组合索引

    多列索引又称组合索引,在mysql的查询操作中,我们经常会遇到多个搜索条件,如:$sql = "select * from article where content='ma4' and t ...

  3. 如何禁止C++默认生成成员函数

    前言: 前几天在一次笔试过程中被问到c++如何设计禁止调用默认构造函数,当时简单的想法是直接将默认构造函数声明为private即可,这样的话对象的确不能直接调用.之后查阅了<Effective ...

  4. hprof教程

    大部分内容参考http://www.linuxidc.com/Linux/2012-04/58178.htm J2SE中提供了一个简单的命令行工具来对java程序的cpu和heap进行 profili ...

  5. Erlang中的图形化检测工具(4)

    这儿例举出若干个用于检视运行时系统的图形化工具,这些工具可以很好地帮助我们增进对系统的理解.借助这些工具,我们可以很好地以图形化方式观察进程.应用和监督层级. (1) Appmon.Appmon 是用 ...

  6. pubwin 客户端会员无法自助结账的排查方法

    客户端会员无法自助结账按以下方法排查:1,看客户端能不能打开web https 后台,打不开的话,在服务端打上2048证书补丁(按下面帖子操作)http://bbs.pubwin.com.cn/for ...

  7. Hough Transform直线检测

    本文原创,如转载请注明出处. Hough Transform 是一种能提取图像中某种特定形状特征的方法,可以将其描述成一种把图像空间中的像素转换成Hough空间中直线或曲线的一种映射函数.通过利用Ho ...

  8. 挖掘机控制器与复制其MCU程序

    最近的时间都浪费在两台小松PW128UU-1上面.旧的一台拆了变速箱,装上去以后就变得换挡不行了.新的一台一直都不行,弄过液压泵以后下部分的行走又出现一时正常一时不动的情况. 先说说概况:PW128U ...

  9. 管理Activity 用户在主界面按两次回退退出系统

    1:定义一个用于管理Activity的类. /* * 用于管理Activity */ public class SysApp extends Application{ private List< ...

  10. CoFun 1616 数字游戏

    Description 一个数x可以按以下规则生成数字: 1.将任意两位交换,若交换的数字为a和b,生成的代价为((a and b)+(a xor b))*2 . 例如134可以生成431,因为431 ...