当前位置:网站首页>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;
}边栏推荐
- Implementation of knowledge consolidation source code 1: epoll implementation of TCP server
- In depth MySQL transactions, stored procedures and triggers
- Knowledge consolidation source code implementation 3: buffer ringbuffer
- 牛顿插值法
- 颠覆你的认知?get和post请求的本质
- Cross domain and jsonp details
- CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
- Mixed development of QML and QWidget (preliminary exploration)
- 关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
- Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
猜你喜欢

Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization

Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code

Recommendation system (IX) PNN model (product based neural networks)

满足多元需求:捷码打造3大一站式开发套餐,助力高效开发

Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)

Selection of slow motion function

Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps

捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统

Introduction to hashtable

Basic use of MySQL (it is recommended to read and recite the content)
随机推荐
English Vocabulary - life scene memory method
Mlapi series - 04 - network variables and network serialization [network synchronization]
Word cover underline
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
1008 circular right shift of array elements (20 points)
QML和QWidget混合开发(初探)
Comprehensive ability evaluation system
Visio draws Tai Chi
Easyrecovery reliable and toll free data recovery computer software
The most detailed and comprehensive update content and all functions of guitar pro 8.0
2/12 didn't learn anything
Lombok原理和同时使⽤@Data和@Builder 的坑
Fedora/REHL 安装 semanage
Ue5 small knowledge points to enable the setting of lumen
MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】
P2102 floor tile laying (DFS & greed)
P2022 有趣的数(二分&数位dp)
How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
Etcd database source code analysis -- etcdserver bootstrap initialization storage
食品行业仓储条码管理系统解决方案