Codeforces Round #435 (Div. 2)
来源:互联网 发布:淘宝按重量标价 编辑:程序博客网 时间:2024/06/05 20:46
D# Codeforces Round #435 (Div. 2)
一波操作稳如狗。
将军,不是我们太弱,是敌人太狡猾啊!!
吐槽一下,谷歌的字体库
突然感觉自己好懒!!
不要再出D这种题好吗? fflush orz~~
正文
Mahmoud and Ehab and the MEX
链接
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly x. the MEX of a set of integers is the minimum non-negative integer that doesn’t exist in it. For example, the MEX of the set {0,2,4} is 1 and the MEX of the set {1,2,3} is 0 .
Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?
Input
The first line contains two integers n and x (1≤n≤100, 0≤x≤100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains n distinct non-negative integers not exceeding 100 that represent the set.
Output
The only line should contain one integer — the minimal number of operations Dr. Evil should perform.
A 题 照例水题
遍历一下,小于x一共几个数,如果已经有x了 在加上一
/******************************************************************* author : touchme-o problem : A time : 2017-09-19 22:56:59 *******************************************************************/#include <iostream>#include <fstream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <time.h>#include <limits.h>#include <assert.h>#include <set>#include <map>#include <stack>#include <queue>#include <list>#include <bitset>#include <vector>using namespace std;#define forn(i, n) for (int i = 0; i < (int)(n); ++i)#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define ForkD(i,k,n) for(int i=n;i>=k;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define pb push_back#define mp make_pair#define fi first#define se second#define vi vector<int>#define pi pair<int,int>#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);#define PRi(a,n) For(i,n-1) cout<<a[i]<<" "; cout<<a[n]<<endl;#define lowbit(x) ((x)&-(x))#define SI(a) ((a).size())#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,0x3f,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define MEMx(a,b) memset(a,b,sizeof(a));#define MAX 105#define INF (0x3f3f3f3f)#define F (1000000007)#define LL long longint n,k,arr[MAX];int main(int argc, char const *argv[]){ // fstream cin("data.in"); // fstream cout("out.txt"); // freopen("data.in", "r", stdin); // freopen("out.txt", "w", stdout); // ios::sync_with_stdio(false); cin>>n>>k;MEM(arr); Rep(i,n) { int x;cin>>x; arr[x]=1; } int ans = 0; Rep(i,k) if(arr[i]==0) ans++; if(arr[k]==1) ans++; cout<<ans<<endl; return 0;}
B. Mahmoud and Ehab and the bipartiteness
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u,v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.
Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn’t contain loops or multiple edges). What is the maximum number of edges they can add?
A loop is an edge, which connects a node with itself. Graph doesn’t contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren’t the same .
Input
The first line of input contains an integer n — the number of nodes in the tree (1≤n≤105).
The next n-1 lines contain integers u and v (1≤u,v≤n,u≠v) — the description of the edges of the tree.
It’s guaranteed that the given graph is a tree.
Output
Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.
已知一棵树,问最多加几条边,可以保证还是二分图
二分图?DFS染色 有两个集合 S,T。 answer = num_s*num_t - n
/******************************************************************* author : touchme-o problem : # time : 2017-09-19 23:12:01 *******************************************************************/#include <iostream>#include <fstream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <time.h>#include <limits.h>#include <assert.h>#include <set>#include <map>#include <stack>#include <queue>#include <list>#include <bitset>#include <vector>using namespace std;#define forn(i, n) for (int i = 0; i < (int)(n); ++i)#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define ForkD(i,k,n) for(int i=n;i>=k;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define pb push_back#define mp make_pair#define fi first#define se second#define vi vector<int>#define pi pair<int,int>#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);#define PRi(a,n) For(i,n-1) cout<<a[i]<<" "; cout<<a[n]<<endl;#define lowbit(x) ((x)&-(x))#define SI(a) ((a).size())#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,0x3f,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define MEMx(a,b) memset(a,b,sizeof(a));#define MAX 100005#define INF (0x3f3f3f3f)#define F (1000000007)#define LL long longint n;std::vector<int> G[MAX];int color[MAX];void DFS(int s,int co) { color[s] = co; for(int i=0;i<G[s].size();i++) { int to = G[s][i]; if(color[to]==0) { DFS(to,-1*co); } }}int main(int argc, char const *argv[]){ // fstream cin("data.in"); // fstream cout("out.txt"); // freopen("data.in", "r", stdin); // freopen("out.txt", "w", stdout); scanf("%d",&n); Rep(i,n-1) { int u,v; scanf("%d%d",&u,&v); G[u].pb(v); G[v].pb(u); } int s1 = 0 ;LL ans = 0 ; DFS(1,1); For(i,n) if(color[i]==-1) s1++; printf("%lld\n",1LL*(n-s1)*s1 - 1LL*n + 1LL); return 0;}
C. Mahmoud and Ehab and the xor
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won’t show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn’t like big numbers, so any number in the set shouldn’t be greater than 106.
Input
The only line contains two integers n and x (1≤n≤105, 0≤x≤105) — the number of elements in the set and the desired bitwise-xor, respectively.
Output
If there is no such set, print “NO” (without quotes).
Otherwise, on the first line print “YES” (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.
构造
/******************************************************************* author : touchme-o problem : # time : 2017-09-20 00:01:00 *******************************************************************/#include <iostream>#include <fstream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <time.h>#include <limits.h>#include <assert.h>#include <set>#include <map>#include <stack>#include <queue>#include <list>#include <bitset>#include <vector>using namespace std;#define forn(i, n) for (int i = 0; i < (int)(n); ++i)#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define ForkD(i,k,n) for(int i=n;i>=k;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define pb push_back#define mp make_pair#define fi first#define se second#define vi vector<int>#define pi pair<int,int>#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);#define PRi(a,n) For(i,n-1) cout<<a[i]<<" "; cout<<a[n]<<endl;#define lowbit(x) ((x)&-(x))#define SI(a) ((a).size())#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,0x3f,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define MEMx(a,b) memset(a,b,sizeof(a));#define MAX 35#define INF (0x3f3f3f3f)#define F (1000000007)#define LL long longint n, x;LL base = 1000000;int main(int argc, char const *argv[]){ // fstream cin("data.in"); // fstream cout("out.txt"); // freopen("data.in", "r", stdin); // freopen("out.txt", "w", stdout); scanf("%d%d", &n, &x); if(n==2 && x==0) return 0*printf("NO\n"); printf("YES\n"); if(n%2==0) printf("0 "),n--; LL ans = 0; Rep(i,n-1) { LL l = base - i; if(i==n-2 && ans^l^x==0) l--; ans = ans ^ l; printf("%d ",l); } printf("%d\n",ans^x); return 0;}
D
want to die
E. Mahmoud and Ehab and the function
Dr. Evil is interested in math and functions, so he gave Mahmoud and Ehab array a of length n and array b of length m. He introduced a function f(j) which is defined for integers j, which satisfy 0 ≤ j ≤ m - n. Suppose, ci = ai - bi + j. Then f(j) = |c1 - c2 + c3 - c4… cn|. More formally, .
Dr. Evil wants Mahmoud and Ehab to calculate the minimum value of this function over all valid j. They found it a bit easy, so Dr. Evil made their task harder. He will give them q update queries. During each update they should add an integer xi to all elements in a in range [li;ri] i.e. they should add xi to ali, ali + 1, … , ari and then they should calculate the minimum value of f(j) for all valid j.
Please help Mahmoud and Ehab.
Input
The first line contains three integers n, m and q (1 ≤ n ≤ m ≤ 105, 1 ≤ q ≤ 105) — number of elements in a, number of elements in b and number of queries, respectively.
The second line contains n integers a1, a2, …, an. ( - 109 ≤ ai ≤ 109) — elements of a.
The third line contains m integers b1, b2, …, bm. ( - 109 ≤ bi ≤ 109) — elements of b.
Then q lines follow describing the queries. Each of them contains three integers li ri xi (1 ≤ li ≤ ri ≤ n, - 109 ≤ x ≤ 109) — range to be updated and added value.
Output
The first line should contain the minimum value of the function f before any update.
Then output q lines, the i-th of them should contain the minimum value of the function f after performing the i-th update .
暴力模拟
#include <bits/stdc++.h>using namespace std;#define FOR(i,s,e) for(int i = (s); i < (e); i++)#define FOE(i,s,e) for(int i = (s); i <= (e); i++)#define FOD(i,s,e) for(int i = (s); i >= (e); i--)#define ll long long#define pb push_back#define mp make_pairset<ll> s;set<ll> :: iterator it;int n, m, x, y, z, k, w, l, r;int A[100005], B[100005];ll sum, tmp;ll solve(ll sum){ ll t1 = -1, t2 = -1; it = s.lower_bound(sum); if (it != s.end()) { t1 = abs(*it - sum); } if (it != s.begin()) { --it; t2 = abs(*it - sum); } if (t1 == -1) return t2; else if (t2 == -1) return t1; else return min(t1, t2);}int main (){ scanf("%d %d %d", &n, &m, &k); FOR(i, 0, n) { scanf("%lld", &A[i]); if (i % 2 == 0) sum += A[i]; else sum -= A[i]; } FOR(i, 0, m) scanf("%lld", &B[i]); FOR(i, 0, m) { if (i % 2 == 0) tmp -= B[i]; else tmp += B[i]; if (i >= n - 1) { if (i >= n) { if ((i - n) % 2 == 0) tmp += B[i - n]; else tmp -= B[i - n]; } if ((i - (n - 1)) % 2 == 0) s.insert(tmp); else s.insert(-tmp); } } printf("%lld\n", solve(-sum)); while (k--) { scanf("%d %d %lld", &l, &r, &tmp); if (r % 2 == 0 && l % 2 == 0) sum -= tmp; else if (r % 2 == 1 && l % 2 == 1) sum += tmp; printf("%lld\n", solve(-sum)); } return 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)
- 主见和索引的区别
- Tian Ji -- The Horse Racing
- Spring学习笔记(五) --- 装配Bean之导入和混合配置
- 深度优先搜索从零突破
- FYN OI 奋斗之路8~
- Codeforces Round #435 (Div. 2)
- 【数学分析】BZOJ1041(HAOI2008)[圆上的整点]题解
- UVA
- Java| Java对象克隆Clone(2)
- 欢迎使用CSDN-markdown编辑器
- 清华第八战告捷!“路漫漫其修远兮,吾将上下而求索”……
- android tv box ---- 插入u盘直接播放指定文件夹中的视频
- 微信小程序入门bug--数据交互(从servlet中获取数据)
- [复习]树状数组 敌兵布阵