输入一个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. 那些容易忽略的事4-(正则表达式反向引用\n)

    n 是一个正整数.一个反向引用(back reference),指向正则表达式中第 n 个括号(从左开始数)中匹配的子字符串. ps1:从左开始数,从左到优,也是从外到里,依次是\1,\2,\3... ...

  2. <转>请戒掉成功学和正能量,那是麻痹人的毒药 | 新知

    非常不幸的是,这将是一场非常糟糕的演说.我不想骗你们,你们从我这里几乎什么也学不到.你们在离开的时候肯定会感到失望,你们的生活并不会得到改善. 更糟糕的是,你还会意识到生活的本质毫无意义,你的一切努力 ...

  3. hadoop之MapReduce WordCount分析

    MapReduce的设计思想 主要的思想是分而治之(divide and conquer),分治算法. 将一个大的问题切分成很多小的问题,然后在集群中的各个节点上执行,这既是Map过程.在Map过程结 ...

  4. 使用python发邮件

    使用python发邮件 网上有很多发邮件的例子,本人在网上找了一份,稍加修改后使用 上源码 # encoding=utf-8 from email.mime.image import MIMEImag ...

  5. Qt窗口句柄

    关键字: 透明效果,异形,子窗口,控件,浮窗,同级句柄

  6. 01--从根源种子CCNode说起

    CCNode作为渲染框架的基类(暂且这样理解,CCObject为引擎基类)其中定义了绘制游戏元素相关的属性以及相关方法.属性当中需要注意的一个是Z坐标,在渲染框架中用来表示元素的遮挡关系,其值越小越容 ...

  7. un ange frappe a ma porte

    Un signe, une larme 魂牵 泪扰 un mot, une arme 字断 情烧 nettoyer les étoiles à l'alcool de mon ame 灵魂之酒眷洗 星 ...

  8. 利用sql命令把结果集输出到文件

    利用sql命令把结果集输出到文件 红色部分的三条命令完成把结果集输出到文件!! [root@test root]# psql -hlocalhost -Utest testWelcome to psq ...

  9. XML Schema <第三篇>

    验证XML文档是否符合议定的XML结构有两种方法,分别是DTD模式与XML Schema.本文主要介绍XML Schema. 一.XML Schema的优点 XML Schema基于XML,没有专门的 ...

  10. UML--一些图

    通过UML来表示汽车,简洁明了. 统一建模语言--UML. 参与者Actor,参与者代表了现实世界的人.人. 用例use case,就是参与者要做什么并且获得什么.事. 业务场景,用例场景.规则. 业 ...