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/ ...
随机推荐
- C++中的int和short int
#include <iostream> #include <string> #include <cstring> //strcpy #include <cst ...
- 多线程中遇到ASSERT(pMap->LookupPermanent(hWndOrig) == NULL);怎么解决
XP下用VC开发的程序,在一个主线程调用3 个线程,线程之间要共享数据,结果总出现wincore.cpp line 980 ASSERT(pMap-> LookupPermane ...
- linux配置备忘
ubuntu英文系统环境下,emacs输入中文设置:(http://www.cnblogs.com/pylemon/archive/2012/01/05/2312682.html) ~/.profil ...
- 微信小程序开发工具 常用快捷键
格式调整 Ctrl+S:保存文件 Ctrl+[, Ctrl+]:代码行缩进 Ctrl+Shift+[, Ctrl+Shift+]:折叠打开代码块 Ctrl+C Ctrl+V:复制粘贴,如果没有选中任何 ...
- URL传值中文乱码
url含有中文 先encodeURI(url)编码 获取之后再解码decodeURI //加密 var param = "itname=" + slRows.ITNAME + &q ...
- iOS数据持久化 -- Core Data-备用
Core Data是一个功能强大的层,位于SQLite数据库之上,它避免了SQL的复杂性,能让我们以更自然的方式与数据库进行交互.Core Data将数据库行转换为OC对象(托管对象)来实现,这样无需 ...
- VS2010下测试程序性能瓶颈
之前看到Qt的有个BUGreport https://bugreports.qt-project.org/browse/QTBUG-13182 这个BUG是在windows下QFileDialog很慢 ...
- bzoj2049-洞穴勘测(动态树lct模板题)
Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好 ...
- 【转】TI-Davinci开发系列之六CCS5.2调试Linux内核
上转博文<TI-Davinci开发系列之五CCS5.2使用gdbserver远程调试应用程序> 使用CCS5.2远程调试内核时,只需导入Linux内核源码,而不需要编译内核,也就不会用到交 ...
- poj 2229 Sumsets(dp 或 数学)
Description Farmer John commanded his cows to search . Here are the possible sets of numbers that su ...