当前位置:网站首页>2022 robocom provincial competition solution
2022 robocom provincial competition solution
2022-07-25 18:41:00 【Find a derivative first】
T4 Given 6 A team , Let's divide into two non empty groups . The question is very simple. , But there are 6 A rule , Logical judgment is troublesome . I learned something here , All can be liberated into the structure , prioritize , The first one after ranking is the optimal solution .
O(2^6 * log(2 ^ 6))
Code:
#include<bits/stdc++.h>
using namespace std;
int cnt[10];
int a[10][5];
int n,m,k,T;
int ans = 1;
struct node{
int x;
bool f1,f2,f3; // The rules 0、1、2
int dis; // The number of people is poor
bool f4; // There are many people on the left
vector<int> l;
bool operator<(const node&rhs)const
{
if(f1 != rhs.f1) return f1 > rhs.f1;
if(f2 != rhs.f2) return f2 > rhs.f2;
if(f3 != rhs.f3) return f3 > rhs.f3;
if(dis != rhs.dis) return dis < rhs.dis;
if(f4 != rhs.f4) return f4 > rhs.f4;
for(int i=0;i<min(l.size(),rhs.l.size());++i)
{
int t1 = l[i],t2 = rhs.l[i];
if(t1 != t2) return t1 < t2;
}
}
}v[100];
void solve()
{
n = 6;
for(int i=0;i<n;++i) cin>>cnt[i];
int t = 0;
for(int i=0;i<n;++i)
{
for(int j=0;j<3;++j)
scanf("%1d",&a[i][j]);
if(a[i][0]) t++;
}
if(t < 2)
{
cout<<"GG";
return ;
}
for(int i=0;i<(1<<6);++i)
{
v[i].x = i;
v[i].f1 = v[i].f2 = v[i].f3 = v[i].f4 = 0;
int x = i;
vector<int> l,r;
for(int i=0;i<n;++i)
{
if(!cnt[i]) continue;
if(x>>i&1) l.push_back(i);
else r.push_back(i);
}
if(!l.size() || !r.size()) continue;
v[i].l = l;
bool f1 = 0,f2 = 0,f3 = 0,f4 = 0,f5 = 0,f6 = 0;
int sum1 = 0,sum2 = 0;
for(int i=0;i<l.size();++i)
{
int x = l[i];
if(a[x][0]) f1 = 1;
if(a[x][1]) f2 = 1;
if(a[x][2]) f3 = 1;
sum1 += cnt[x];
}
for(int i=0;i<r.size();++i)
{
int x = r[i];
if(a[x][0]) f4 = 1;
if(a[x][1]) f5 = 1;
if(a[x][2]) f6 = 1;
sum2 += cnt[x];
}
if(f1 && f4) v[i].f1 = 1;
if(f2 && f3 && f5 && f6) v[i].f2 = 1;
if(f3 && f6) v[i].f3 = 1;
v[i].dis = abs(sum1-sum2);
if(sum1 > sum2) v[i].f4 = 1;
else v[i].f4 = 0;
}
sort(v,v+64);
int x = v[0].x;
vector<int> l,r;
for(int i=0;i<n;++i)
{
if(!cnt[i]) continue;
if(x>>i&1) l.push_back(i+1);
else r.push_back(i+1);
}
for(int i=0;i<l.size();++i)
{
if(i) cout<<" ";
cout<<l[i];
}
cout<<"\n";
for(int i=0;i<r.size();++i)
{
if(i) cout<<" ";
cout<<r[i];
}
}
signed main(void)
{
solve();
return 0;
}
T5
The question :
set up G=(V,E) It's an undirected graph , If vertex set V It can be divided into two disjoint subsets (A,B), And every side (i,j)∈E Two endpoints of i and j Belong to these two different sets of vertex points , It's called a picture G For a bipartite graph .
Now give a tree T, It is required to select two nodes without edge connection in the tree i and j, Make the undirected edge (i,j) add T Then it can form a bipartite graph . Your task is to calculate how many options meet this requirement .
Ideas : First , A given tree must be a bipartite graph , Because acyclic , The dots on both sides of each edge can be dyed in black and white . that , We can dye the given tree in black and white , Suppose the black node has x individual , White nodes are the rest n-x individual . All black nodes are connected to white nodes , At most x*(n-x), Originally there were n-1 side , The plan is the difference between the two , These edges can be added once respectively .
O(n)
Code:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
vector<int> va[N];
int n,m,k,T;
bool vis[N];
void dfs(int cur,int fa,bool st)
{
vis[cur] = st;
for(int i=0;i<va[cur].size();++i)
{
int j = va[cur][i];
if(j==fa) continue;
dfs(j,cur,!st);
}
}
void solve()
{
cin>>n;
for(int i=0;i<n-1;++i)
{
int x,y; cin>>x>>y;
va[x].push_back(y),va[y].push_back(x);
}
dfs(1,0,1);
int l = 0,r = 0;
for(int i=1;i<=n;++i)
{
if(vis[i]) l++;
}
r = n-l;
long long ans = 1ll*l*r;
ans -= (n-1);
cout<<ans;
}
signed main(void)
{
solve();
return 0;
}
边栏推荐
- Jz32 print binary tree from top to bottom
- Tensor to img & imge to tensor (tensor conversion of pytorch)
- 通讯录(二)
- 2022年IAA行业品类发展洞察系列报告·第二期
- Nc78 reverse linked list
- 《21天精通TypeScript-4》-类型推断与语义检查
- 拍卖行作VC,第一次出手就投了个Web3
- 华为年内二度招聘“天才少年”;540万Twitter账号信息泄露,卖价3万美元;谷歌解雇了相信AI有意识的工程师|极客头条
- Vc/pe is running towards Qingdao
- Chapter 5 Basic Scripting: Shell Variables
猜你喜欢

【帮助中心】为您的客户提供自助服务的核心选项

从目标检测到图像分割简要发展史

Powell's function of Ceres

华为年内二度招聘“天才少年”;540万Twitter账号信息泄露,卖价3万美元;谷歌解雇了相信AI有意识的工程师|极客头条

pd.melt() vs reshape2::melt()

Care for front-line epidemic prevention workers, Haocheng JIAYE and Gaomidian sub district office jointly build the great wall of public welfare

One week activity express | in simple terms, issue 8; Meetup Chengdu station registration in progress

Software testing -- common testing tools

如何创建一个有效的帮助文档?

软件测试进阶篇—测试分类
随机推荐
Automatic machine learning library: Tpot の learning notes
VC/PE正跑向青岛
[QNX hypervisor 2.2 user manual]9.5 dump
[haoi2015] tree operation
Safe operation instructions for oscilloscope probe that must be read by engineers
动态内存管理
市值300亿,欧洲十年来最大IPO再冲纽交所
Uniapp scroll bar topping effect, customized page scroll bar position (sorting)
Partial correlation calculation of R language and partial correlations calculation using pcor function of GGM package
可视化模型网络连接
华为年内二度招聘“天才少年”;540万Twitter账号信息泄露,卖价3万美元;谷歌解雇了相信AI有意识的工程师|极客头条
从目标检测到图像分割简要发展史
What are the methods of traversing arrays? What is the difference between the performance of the for loop foreach for/in for/of map and how to choose?
软件测试进阶篇—测试分类
Disk performance and capacity
进程通信(SystemV通信方式:共享内存,消息队列,信号量)
Typescript对象代理器Proxy使用
Paper revision reply 1
Qtimgui 编译
浅析回归问题、建模、预测