当前位置:网站首页>Uva1592 Database
Uva1592 Database
2022-07-06 04:33:00 【Pecksniff. k】
The original title is :
Ideas : Use one IDcache To assign all strings ID, recycling pair Form a binary . Maintain left endpoint c1, Enumerate right endpoints c2, At the same time through row Scan the assigned from top to bottom id library . Query the first row That's ok pair(c1,c2) Whether it exists or not .
Code :
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>// aggregate
#include<map>// mapping
#include<vector>// vector
#include<utility>//pair
#define DEBUG
using namespace std;
map<string,int> IDcache;// Record ID
map<pair<int,int>,int> Binary_pair;// Record where the binary is row
int cnt=0;
int ID(string s)// Distribute ID
{
if(IDcache.count(s))
{
return IDcache[s];
}
else
{
return IDcache[s]=cnt++;
}
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
while(cin>>n>>m)
{
IDcache.clear();
Binary_pair.clear();
vector<vector<int>> dict(n,vector<int>(m));// Deposit ID
string s;
cnt=0;
cin.get();// Eliminate line breaks
for(int i=0;i<n;i++)
{
getline(cin,s);
for(int j=0;j<s.length();j++)
{
if(s[j]==',')
{
s[j]=' ';// Replace commas with spaces
}
else if(s[j]==' ')
{
s[j]=',';// Replace the space with an impossible comma
}
}
stringstream ss(s);// Character stream
for(int j=0;j<m;j++)
{
string cur;
ss>>cur;
dict[i][j]=ID(cur);
}
}
#ifndef DEBUG// Debug statement
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<dict[i][j]<<" ";
}
cout<<endl;
}
#endif
if(m>1)
{
for(int c1=0;c1<m-1;c1++)// Maintain left endpoint
{
for(int c2=c1+1;c2<m;c2++)// Enumerate right endpoints
{
Binary_pair.clear();
for(int row=0;row<n;row++)// Traverse from top to bottom
{
pair<int,int> temp(dict[row][c1],dict[row][c2]);
if(Binary_pair.count(temp))// Is not Peter normal form
{
cout<<"NO"<<endl;
cout<<Binary_pair[temp]+1<<" "<<row+1<<endl;
cout<<c1+1<<" "<<c2+1<<endl;
goto out;// Jump out of multiple loops
}
else
{
Binary_pair[temp]=row;
}
}
}
}
}
cout<<"YES"<<endl;
out:;
}
return 0;
}
边栏推荐
- [Zhao Yuqiang] deploy kubernetes cluster with binary package
- VPP性能测试
- The value of two date types is subtracted and converted to seconds
- Lagrange polynomial
- 10 exemples les plus courants de gestion du trafic istio, que savez - vous?
- Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
- flink sql 能同时读多个topic吗。with里怎么写
- 【Try to Hack】john哈希破解工具
- Word cover underline
- 深入浅出node模板解析错误escape is not a function
猜你喜欢
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
Comprehensive ability evaluation system
About some basic DP -- those things about coins (the basic introduction of DP)
Visio draw fan
Cross domain and jsonp details
English Vocabulary - life scene memory method
Slow SQL fetching and analysis of MySQL database
[face recognition series] | realize automatic makeup
The most detailed and comprehensive update content and all functions of guitar pro 8.0
Dry goods collection | Vulkan game engine video tutorial
随机推荐
2/12 didn't learn anything
Solve the compilation problem of "c2001: line breaks in constants"
Lombok原理和同时使⽤@Data和@Builder 的坑
729. My schedule I (set or dynamic open point segment tree)
P2022 有趣的数(二分&数位dp)
Basic explanation of turtle module - draw curve
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
我想问一下 按照现在mysql-cdc的设计,全量阶段,如果某一个chunk的binlog回填阶段,
ETCD数据库源码分析——etcdserver bootstrap初始化存储
[HBZ sharing] how to locate slow queries in cloud database
[face recognition series] | realize automatic makeup
1291_Xshell日志中增加时间戳的功能
Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
Can CDC pull the Oracle table in full
[HBZ share] reasons for slow addition and deletion of ArrayList and fast query
Yyds dry goods inventory OSI & tcp/ip
VNCTF2022 WriteUp
[leetcode question brushing day 33] 1189 The maximum number of "balloons", 201. The number range is bitwise AND
Lora gateway Ethernet transmission
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0