D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play a computer game where you have to breed some magical creatures. Initially, they have k creatures numbered from 1 to k. Creatures have n different cha…
传送门 题目大意: 输入给出一串位运算,输出一个步数小于等于5的方案,正确即可,不唯一. 题目分析: 英文题的理解真的是各种误差,从头到尾都以为解是唯一的. 根据位运算的性质可以知道: 一连串的位运算最终都可以用三个位运算代替(&|^). 那么仅需对每一位的情况进行讨论,某一位: 必须变为1 (|1) 必须变为0 (&0) 必须01颠倒(^1) 最后输出3种位运算即可(输出三种最稳妥). code #include<bits/stdc++.h> using namespace…
题解: 首先,我们可以用 dfsdfsdfs 在 O(n)O(n)O(n) 的时间复杂度求出初始状态每个点的权值. 不难发现,一个叶子节点权值的取反会导致根节点的权值取反当且仅当从该叶子节点到根节点这一条链上的每个点的权值都被取反(都被影响到).而这4种逻辑运算中,NOTNOTNOT 和 XORXORXOR 是最简单的,即只要2个儿子中的一个儿子的值被取反,该点的值就会被取反.但 ANDANDAND 和 OROROR 存在只修改一个儿子时不会对该点的权值产生影响的情况,这就需要我们进行一下特判.…
题意: 求n个数中两两和的异或. 思路: 逐位考虑,第k位只需考虑0~k-1位,可通过&(2k+1-1)得到一组新数. 将新数排序,当两数和在[2k,2k+1)和[2k+1+2k,2k+2)之间时该位为1,又因为两数的最大和为2*(2k+1-1)=2k+2-2, 即当两数和在[2k,2k+1)和[2k+1+2k,2k+2-2]之间时该位为1. 对于每个数,找到和 大于等于2k 小于2k+1 大于等于2k+1+2k 的三个临界点(因为两数之和一定小于等于2k+2-2,所以第四个临界点可以忽略),…
Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main(){ , s, d; scanf("%d", &n); while(n--) { scanf("%d%d", &a…
A. Short Program link http://codeforces.com/contest/878/problem/A describe Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language…
A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/problem/A Description Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the…
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single soluti…
题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cstdio> #include<cstring> #include<map> using namespace std; + ; const int INF = 2e9; typedef __int64 LL; int n, k; int x[maxn], y[maxn]; bool…
A. Magic Spheres   Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he nee…