暴搜 #include<cstdio> #include<algorithm> using namespace std; int n,K,Div=1,a[21],m,ans=100; bool vis[21]; void calc(int now) { int t=0; bool flag=0; for(int i=m;i>=1;--i) if(!vis[i]) { if((!flag) && a[i]==0) return; t=t*10+a[i]; fla…
题意:给你一张图,给你每个点的权值,要么是-1,要么是1,要么是0.如果是-1就不用管,否则就要删除图中的某些边,使得该点的度数 mod 2等于该点的权值.让你输出一个留边的方案. 首先如果图内有-1,那么必有解.否则如果初始不合法的点数为偶数,那么必有解,否则无解.因为删一条边,要么使图中不合法的点数+2,要么不变,要么-2. 如果有解,构造图的任意一个生成树,如果有-1,就让-1为根,否则任意结点为根.然后从叶子向根定每个点的入度数,由于自底向上,一个结点的儿子边都被处理完后,只需要决定父边…
从任意点出发,贪心染色即可. #include<cstdio> #include<algorithm> using namespace std; int v[200010<<1],next[200010<<1],first[200010],e; void AddEdge(int U,int V) { v[++e]=V; next[e]=first[U]; first[U]=e; } bool vis[200010]; int n,col[200010]; v…
设sum是所有灯泡的亮度之和 有两种情况: 一种是存在结点U和V,U是V的祖先,并且U的子树权值和为sum/3*2,且U不是根,且V的子树权值和为sum/3. 另一种是存在结点U和V,他们之间没有祖先关系,两者的子树权值和都是sum/3.(已经出栈的结点和当前访问的结点之间,必然没有祖先关系) 两次dfs解决. #include<cstdio> #include<algorithm> #include<cstdlib> using namespace std; int…
按位考虑,每个变量最终的赋值要么是必为0,要么必为1,要么和所选定的数相同,记为2,要么和所选定的数相反,记为3,一共就这四种情况. 可以预处理出来一个真值表,然后从前往后推导出每个变量的赋值. 然后从高位到低位考虑,如果某一位,对于所有变量而言,2的数量大于等于3的数量,就把所选定的数的该位记为0,否则记为1,就能满足和最小.反之就能满足和最大. #include<cstdio> #include<string> #include<iostream> #include…
按照b[i]-a[i],对物品从大到小排序,如果这个值大于零,肯定要立刻购买,倘若小于0了,但是没买够K个的话,也得立刻购买. #include<cstdio> #include<algorithm> using namespace std; struct Point { int x,y; }a[200010]; int n,K,ans; bool cmp(const Point &a,const Point &b) { return a.y-a.x>b.y-…
一次交换,会让Group A里面的某个数字的数量-1,另一个数字的数量+1:对Group B恰好相反. 于是答案就是xigma(i=1~5,numA[i]-numB[i]>0)(numA[i]-numB[i])/2,如果这个值无法被2整除,则无解,或者如果这个值不等于xigma(i=1~5,numA[i]-numB[i]<0)(-numA[i]+numB[i])/2的话,也无解. 或者如果某个值在两组中出现的总次数无法被2整除,也无解. #include<cstdio> using…
本篇为 Codeforces Round #798 (Div. 2) 也就是 CF1689 的题解,因本人水平比较菜,所以只有前四题 A.Lex String 题目描述 原题面 给定两个字符串 \(a,b\),要求通过以下的两种操作构造一个新的字符串 \(c\),使得 \(c\) 的字典序最小,并且要求不能连续使用某一种操作超过 \(k\) 次 1.从 \(a\) 中任选一个字符插入到 \(c\) 的末尾 2.从 \(b\) 中任选一个字符插入到 \(c\) 的末尾 若某一个字符串为空则认为构造…
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed…
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segmen…