当前位置:网站首页>Codeforces round 770 (Div. 2) e. fair share
Codeforces round 770 (Div. 2) e. fair share
2022-07-28 17:09:00 【Code92007】
subject
m(1<=m<=1e5) An array , The first i The length of arrays is ni(2<=ni<=2e5,ni For the even )
The first i The... In the array j It's worth aij(1<=aij<=1e9),sumni<=2e5
Ask if you can divide these integers into two multiset, It might be called L The collection and R aggregate ,
So that exactly half of the elements in each array are L Within collection , The other half of the element is R Within collection ,
And L The collection and R The set is ultimately the same multiset
Source of ideas
palayutm、wifiii Code
Answer key
If you think of the structure of Euler circuit , It's easy to do
First, consider the case of no solution , A certain number appears an odd number of times , There must be no solution ; otherwise , There must be a solution
First discretize the numbers , Then here is a way of composition :
The first i Array ,ai0 and ai1 Even without direction ,ai2 and ai3 Even without direction , And so on
amount to ai0 and ai1 On different sides of the bipartite graph ,ai2 and ai3 Empathy ,
You can find , For each point on the graph ( The number after discretization ) Come on ,
Because the number of occurrences is even , So the degree is even , So the Euler circuit must have a solution
In a certain scheme of Euler loop , edge x It's from No i An array of a Value points to b It's worth it ,
Orient the edges , Might as well give b Value divided into R aggregate , to a Value divided into L aggregate
No matter how the edges in the same array are oriented , Half of them belong to L, The other half belongs to R
And for every number v Come on , Just one half of it comes from v Starting point to other points , The other half starts from other points and returns v
Try it here c11 and c17 The grammar of , I think it's very good
Experience
Think in reverse , Why do you build a map like this ,
Because each number appears to be an even number , So each aij One side , It can ensure that the Euler circuit has a solution
Because there is just ni/2 One is located in L aggregate , another ni/2 One is located in R aggregate ,
So it's equivalent to ni/2 For mutual exclusion , It corresponds to building in each array ni/2 Pair the edges in pairs ,
When orienting the edge , Place adjacent points in different sets , That's how it works
This is related to the official explanation , Left point of bipartite graph i It means the first one i An array , On the right j Representation number j Mapping method , The essence is consistent
Code
#include<bits/stdc++.h>
using namespace std;
void fast(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
int main(){
fast();
int m,n;
cin>>m;
vector<vector<int> >a(m),ans(m);
vector<int>b;
for(int i=0;i<m;++i){
cin>>n;
a[i].resize(n);
ans[i].resize(n);
for(int j=0;j<n;++j){
cin>>a[i][j];
b.push_back(a[i][j]);
}
}
sort(b.begin(),b.end());
b.erase(unique(b.begin(),b.end()),b.end());
vector<int>deg(b.size());
for(int i=0;i<m;++i){
for(auto &v:a[i]){
v=lower_bound(b.begin(),b.end(),v)-b.begin();
deg[v]++;
}
}
for(auto &v:deg){
if(v&1){
cout<<"NO"<<endl;
return 0;
}
}
vector<vector<array<int,4>> >e(b.size());
int id=0;
for(int i=0;i<m;++i){
for(int j=1;j<a[i].size();j+=2){
e[a[i][j]].push_back({a[i][j-1],i,j,id});
e[a[i][j-1]].push_back({a[i][j],i,j-1,id});
id++;
}
}
vector<bool>vis(id);
function<void(int)> dfs = [&](int u){
while(!e[u].empty()){
auto [v,i,j,id]=e[u].back();
e[u].pop_back();
if(vis[id])continue;
vis[id]=1;
ans[i][j]=1;
dfs(v);
}
};
for(int i=0;i<b.size();++i){
dfs(i);
}
cout<<"YES"<<endl;
for(int i=0;i<m;++i){
for(auto &v:ans[i]){
cout<<(v?'L':'R');
}
cout<<endl;
}
return 0;
}边栏推荐
- 2020Q2全球平板市场出货大涨26.1%:华为排名第三,联想增幅最大!
- MD5 encryption verification
- 记录开发问题
- PostgreSQL weekly news - July 20, 2022
- Semtech推出物联网地理定位解决方案LoRa Edge,首款芯片LR1110现已上市
- It is said that NVIDIA has held talks with Softbank and will offer more than US $32billion to acquire arm
- Some suggestions on Oracle SQL tuning
- [deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)
- Some opinions on bug handling
- Games101 section 13 ray tracing notes
猜你喜欢

【深度学习】:《PyTorch入门到项目实战》第七天之模型评估和选择(上):欠拟合和过拟合(含源码)

Ugui learning notes (II) Scrollview related

TCP handshake, waving, time wait connection reset and other records

Games101-assignment05 ray tracing - rays intersect triangles

Re11:读论文 EPM Legal Judgment Prediction via Event Extraction with Constraints
![[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)
![[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)

RE14: reading paper illsi interpretable low resource legal decision making

Easypoi --- excel file export
![[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: model evaluation and selection on the seventh day of pytorch introduction to project practice (Part 1): under fitting and over fitting (including source code)
随机推荐
Re10:读论文 Are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr
向高通支付18亿美元专利费之后,传华为向联发科订购了1.2亿颗芯片!官方回应
时间复杂度
[deep learning]: the second day of pytorch introduction to project practice: realize linear regression from zero (including detailed code)
Unity shader global fog effect
Unity3d shader achieves ablation effect
kubenertes 1.16集群部署问题总结
Outline and principle of structured design -- modularization
[deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation
【深度学习】:《PyTorch入门到项目实战》:简洁代码实现线性神经网络(附代码)
Leetcode647. Palindrome substring
综合设计一个OPPE主页--页面的售后服务
Alibaba cloud MSE supports go language traffic protection
[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)
做题笔记4(第一个错误的版本,搜索插入位置)
Leetcode70 suppose you are climbing stairs. You need n steps to reach the roof. You can climb one or two steps at a time. How many different ways can you climb to the roof?
Leetcode9. Palindromes
Applet: scroll view slides to the bottom by default
go语言慢速入门——流程控制语句
华为Mate 40系列曝光:大曲率双曲面屏,5nm麒麟1020处理器!还将有天玑1000+的版本