当前位置:网站首页>CF1634E Fair Share
CF1634E Fair Share
2022-07-05 05:31:00 【solemntee】
The question : Yes m m m An array , The number of numbers in each array is even . Divide each array in half to the set A 、 B A、B A、B Make the final resettable same, judge whether it is legal, and give the scheme .
First of all, I probably only think of Euler circuit on the court , But because there is no demolition point to build a map , We can only do the case of non re set , Later, I had no choice but to broadcast .
The method is to create a bipartite map , Left m m m Dots represent each array , Right c n t cnt cnt( Number of digital categories ) A little bit .
Numbers from the left to the right i i i The directed edge of represents i i i among A A A aggregate , On the contrary, it means to give B B B aggregate . It is easy to know that the original problem is equivalent to searching Euler circuits on bipartite graphs .
Then because there is no need to output the path , Just dye the edges with black and white , Then keep searching the ring .
Then finding a ring will not affect the Euler circuit property of the complementary graph , It is also obvious that Euler can definitely search a ring , That's it .
By the way, please enjoy the new one l a m b d a lambda lambda function
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int m;
scanf("%d",&m);
vector<vector<int>>a(m+1),ans(m+1);
map<int,int>mp,cnt;
int asdf=0;
for(int i=1;i<=m;i++)
{
int n;
scanf("%d",&n);
a[i].resize(n+1);
ans[i].resize(n+1,-1);
for(int j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
if(mp[a[i][j]]==0)mp[a[i][j]]=++asdf;
cnt[mp[a[i][j]]]++;
}
}
for(int i=1;i<=asdf;i++)if(cnt[i]%2==1)
{
printf("NO");
return 0;
}
vector<vector<pair<int,int>>>gra(4e5+5);
vector<int>cur(4e5+5);
const int MX=2e5;
for(int i=1;i<=m;i++)
{
for(int j=1;j<a[i].size();j++)
{
gra[i].push_back({
mp[a[i][j]]+MX,j});
gra[MX+mp[a[i][j]]].push_back({
i,j});
cur[i]++;
cur[MX+mp[a[i][j]]]++;
}
}
function<void(int,int)>dfs=[&](int now,int flag)
{
int u=now;
while(cur[u])
{
cur[u]--;
auto [to,pos]=gra[u][cur[u]];
while(ans[min(u,to)][pos]<0)
{
ans[min(u,to)][pos]=flag;
dfs(to,1-flag);
}
}
};
for(int i=1;i<=m;i++)dfs(i,0);
printf("YES\n");
for(int i=1;i<=m;i++)
{
for(int j=1;j<ans[i].size();j++)
{
if(ans[i][j]==0)printf("L");
else printf("R");
}
printf("\n");
}
return 0;
}
边栏推荐
- TF-A中的工具介绍
- 软件测试 -- 0 序
- SAP method of modifying system table data
- 质量体系建设之路的分分合合
- kubeadm系列-01-preflight究竟有多少check
- [turn to] MySQL operation practice (III): table connection
- 搭建完数据库和网站后.打开app测试时候显示服务器正在维护.
- [turn to] MySQL operation practice (I): Keywords & functions
- Chapter 6 data flow modeling - after class exercises
- Acwing 4301. Truncated sequence
猜你喜欢
剑指 Offer 09. 用两个栈实现队列
质量体系建设之路的分分合合
Graduation project of game mall
Sword finger offer 05 Replace spaces
Sword finger offer 35 Replication of complex linked list
Gbase database helps the development of digital finance in the Bay Area
Yolov5 adds attention mechanism
剑指 Offer 05. 替换空格
Solution to the palindrome string (Luogu p5041 haoi2009)
【Jailhouse 文章】Look Mum, no VM Exits
随机推荐
To the distance we have been looking for -- film review of "flying house journey"
SAP-修改系统表数据的方法
ALU逻辑运算单元
After setting up the database and website When you open the app for testing, it shows that the server is being maintained
Light a light with stm32
剑指 Offer 09. 用两个栈实现队列
Summary of Haut OJ 2021 freshman week
PC寄存器
[depth first search] 695 Maximum area of the island
剑指 Offer 53 - I. 在排序数组中查找数字 I
数仓项目的集群脚本
Sword finger offer 53 - ii Missing numbers from 0 to n-1
Solution to the palindrome string (Luogu p5041 haoi2009)
Drawing dynamic 3D circle with pure C language
kubeadm系列-02-kubelet的配置和启动
Double pointer Foundation
过拟合与正则化
A problem and solution of recording QT memory leakage
Time complexity and space complexity
lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8