UVa1592 数据库(摘)
输入一个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 (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 = + ;
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 数据库(摘)的更多相关文章
- JSP应用开发 -------- 电纸书(未完待续)
http://www.educity.cn/jiaocheng/j9415.html JSP程序员常用的技术 第1章 JSP及其相关技术导航 [本章专家知识导学] JSP是一种编程语言,也是一种动 ...
- 【摘】Mysql备份还原数据库之mysqldump实例及参数详细说明
原文http://www.cnblogs.com/xuejie/archive/2013/01/11/2856911.html 我们在运营项目的过程中肯定会遇到备份数据库,还原数据库的情况,我们一 ...
- C#-VS SQLServer数据库编程-摘
ado.net 通用类对象.在本地内存暂存数据 托管类对象.让本地通用类对象连接数据库,让本地通用类对象和数据库同步 连接数据库 new connection(connectstring) comma ...
- 摘:用ADO操作数据库的方法步骤
用ADO操作数据库的方法步骤 ADO接口简介 ADO库包含三个基本接口:_ConnectionPtr接口._CommandPtr接口和_RecordsetPtr接口. _ConnectionPtr接口 ...
- 摘:VC开发数据库基础之ADO篇
一.ADO简介ADO(ActiveX Data Object)是Microsoft数据库应用程序开发的新接口,是建立在OLE DB之上的高层数据库访问技术,请不必为此担心,即使你对OLE DB,COM ...
- 摘:C++:用ADO操作数据库的方法步骤
ADO接口简介 ADO库包含三个基本接口:_ConnectionPtr接口._CommandPtr接口和_RecordsetPtr接口. _ConnectionPtr接口返回一个记录集或一个空指针 ...
- 算法习题---5.9数据库(Uva1592)
一:题目 对数据库中数据进行检测,是否出现数据冗余现象.即是否某一列出现两个及以上数据重复 如上图中,第二列中第2,3行数据重复,所以我们判断为数据冗余.因为他可以分解为下面两张表 (一)样例输入 H ...
- 对象和数据库的天然阻抗 转摘于:http://www.jdon.com/mda/oo-reltaion2.html
在“面向对象建模与数据库建模两种分析设计方法的比较”一文中我们比较了在对需求分析时两种方法的不同,所谓数据库建模分析,就是项目一开始就根据需求建立数据库模型,如数据表结构和字段等,这种错误现象大量普遍 ...
- PL/SQL Developer连接本地Oracle 11g 64位数据库
转摘:http://www.cnblogs.com/ymj126/p/3712727.html 用于学习,笔记,以备后用. 1.登录PL/SQL Developer 这里省略Oracle数据库和PL/ ...
随机推荐
- 4、记录1----获取hdfs上FileSystem的方法 记录2:正则匹配路径:linux、hdfs
/** * 获取hadoop相关配置信息 * @param hadoopConfPath 目前用户需要提供hadoop的配置文件路径 * @return */ public static Config ...
- QT5-控件-QComboBox
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QComboBox> cl ...
- volatile举列说明const
1.即使本程序中虽然不改变这种类型的值,但别的比如中断程序可能会改变这个值,加上volatile,编译器不优化,每次都重新访问这个值做判断 2.如 unsigned char flag = 1; in ...
- <Win32_5>深入浅出Win32的计时器
说起时间,对于我们搞IT的人来说,那是要多重要有多重要.我觉得有价值的时间是给有抱负和有才能的人准备的,因为他们会充分利用,不会让时间失望…… 呵呵,有点儿说远了,还是回归主题吧 Win32的计时器其 ...
- /users/products.:format 这种写法的其对应解析字符写法
“products.:format" 这种写法可以有对应的下面两种路由形式 /products.json /products.xml "products.:format?" ...
- 安装Oracle10g on RedHat as 4 64bit(摘)
一.安装前的配置 1.修改RH版本 vi /etc/redhat-release Red Hat Enterprise Linux AS release 3 (Taroon Update 3) 2. ...
- 考查嵌入式C开发人员的最好的16道题
约定: 1) 下面的测试题中,认为所有必须的头文件都已经正确的包含了 2)数据类型 char 一个字节 1 byte int 两个字节 2 byte ( ...
- 〔写在OS边上〕定性note
转载:http://tieba.baidu.com/p/1273477757 0 neta 有的时候我们在读书或者看文档.——啊,原来这东西的框架就是这样而已,很直白么.有的时候我们在读代码.——于是 ...
- javabeans的运用
javabeans的运用 对javabean的使用我开始严重的郁闷,跟着书上说的做,但是总是不成功.后来别人说我是基础不牢靠.我觉得应该从servlet学起然后再加进入JSP学是非常快的,对于JAVA ...
- 【转】Android下编译jni库的二种方法(含示例)
原文网址:http://blog.sina.com.cn/s/blog_3e3fcadd01011384.html 总结如下:两种方法是:1)使用Android源码中的Make系统2)使用NDK(从N ...