Codeforces Round #435 (Div. 2)
来源:互联网 发布:php代码美化 编辑:程序博客网 时间:2024/06/05 23:46
http://codeforces.com/contest/862
A。给定一个数组,问你最少改变多少的数,能够让这个数组中第一个不出现的数为x
直接记录x之前的数,用x减去就行,注意当x出现再数组中时,加一个删除操作。
#include <bits/stdc++.h>using namespace std;const int maxn=103;int num[maxn];int main(){ int m,n,s; while(~scanf("%d%d",&m,&n)){ memset(num,0,sizeof(num)); for(int i=1;i<=m;i++){ scanf("%d",&s); num[s]=1; } int all=0; for(int i=0;i<n;i++){ if(num[i]) all++; } if(num[n]) printf("%d\n",n-all+1); else printf("%d\n",n-all); } return 0;}
2 问你把这个图作成二分图,最少还能加多少边。要求没有自环没重边。
染色法,统计数目就行。
#include <bits/stdc++.h>using namespace std;/* 我觉得,隔着搜索,然后把他们入一vector。 判断一下siz就行了,*/typedef long long ll;const int maxn=2e5+3000;int vis[maxn];ll m;struct Node{ int to,next;}node[maxn*2];int len;int head[maxn];void add(int a,int b){ node[len].to=b; node[len].next=head[a]; head[a]=len++;}void init(){ len=0; memset(head,-1,sizeof(head));}void dfs(int u,int col){ vis[u]=col; for(int i=head[u];i!=-1;i=node[i].next){ int to=node[i].to; if(vis[to]!=-1) continue; dfs(to,1-col); }}int main(){ int a,b; while(~scanf("%lld",&m)){ init(); for(int i=0;i<m-1;i++){ scanf("%d%d",&a,&b); add(a,b); add(b,a); } memset(vis,-1,sizeof(vis)); dfs(1,0); ll sum=0; for(int i=1;i<=m;i++){ if(vis[i]==1) sum++; } //printf("%d",sum); //cout<<endl; printf("%lld\n",sum*(m-sum)-m+1); } return 0;}
阅读全文
0 0
- Codeforces Round #435 div 2
- Codeforces Round #435 (Div. 2)
- Codeforces Round #435 (Div. 2)
- Codeforces Round #435 (Div. 2)
- [Codeforces]Round #435 (Div. 2)
- Codeforces Round #435 (Div. 2)
- Codeforces Round #435 (Div. 2)
- Codeforces Round #435 (Div. 2)
- Codeforces Round #435 (Div. 2) (思路题)
- Codeforces Round #435 (Div. 2) 题解
- Codeforces Round #435 (Div. 2) 题解
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- 对象关系映射
- 数据结构 第5讲 顺序栈
- Unexpected 'a' 错误
- Android7.1的存储空间监控
- stdc++.h
- Codeforces Round #435 (Div. 2)
- input 输入值并显示总结【初学者】
- ㈡Eclipse/MyEclipse使用Maven配置SpringMVC
- 解决checkbox的attr(checked)一直为undefined问题
- java远程调用
- 字符串操作的一些陷阱,谨记!
- cordova项目创建过程
- (记录)面试遇到的中间自适应,两端固定的三列布局
- iis7.5 php进程意外退出,错误代码 0xfffffffe