Codeforces Problem 778B Bitwise Formula】的更多相关文章

题目链接:http://codeforces.com/contest/779/problem/E 题意:有n个变量都可以用m位二进制数表示,这n个数的value将以两种格式中的一种给出 1.变量名, 空格, ":=", 空格, 一个正好m位的二进制数 eg(m = 3):   a := 101 2.变量名, 空格, ":=", 空格, 第一个变量, 空格, 位运算符(AND,OR,XOR), 空格, 第二个变量 每一个变量都是前面被定义过的变量或者用 '?'表示 e…
题意: 选择一个 m 位的二进制数字,总分为 n 个算式的答案之和.问得到最低分和最高分分别应该取哪个二进制数字 分析: 因为所有数字都是m位的,高位的权重大于低位 ,我们就从高到低考虑 ans 的每一位是取 0 还是取 1,统计该位的权重(即n个式子该位结果之和)即可. #include <bits/stdc++.h> using namespace std; int n, m; map<string, int> mp; struct query{ string f; int n…
[题目链接]:http://codeforces.com/contest/779/problem/E [题意] 给你n个长度为m的二进制数 (有一些是通过位运算操作两个数的形式给出); 然后有一个未知数字,用符号'?'表示; (所有的数字都是长度为m的二进制数); 然后让你确定这个'?'使得n个数字的和最大.最小; [题解] 模拟题; 会有嵌套的情况: 即 a=x & y b=a&? 类似这样. 所以在算b之前,先把a的值确定下来; 明白了怎么算之后; 枚举那个未知数字的m位的每一位; 每…
Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Consider 10 Boolean variables x1, x2, x3, x4, x5, x6, x7, x8, x9, and x10. Consider all pairs and triplets of distinct variables amon…
位运算,枚举. 按按分开计算,枚举$?$是$0$还是$1$,分别计算出$sum$,然后就可以知道该位需要填$1$还是$0$了. #include<map> #include<set> #include<ctime> #include<cmath> #include<queue> #include<string> #include<vector> #include<cstdio> #include<cstr…
按位考虑,每个变量最终的赋值要么是必为0,要么必为1,要么和所选定的数相同,记为2,要么和所选定的数相反,记为3,一共就这四种情况. 可以预处理出来一个真值表,然后从前往后推导出每个变量的赋值. 然后从高位到低位考虑,如果某一位,对于所有变量而言,2的数量大于等于3的数量,就把所选定的数的该位记为0,否则记为1,就能满足和最小.反之就能满足和最大. #include<cstdio> #include<string> #include<iostream> #include…
 题目链接: http://codeforces.com/problemset/problem/708/A 题目大意: 从字符串s中挑选出一个子串(非空),将该子串中的每个字母均替换成前一个字母,如'b'换成'a','c'换成'b',以此类推,特别的,'a'要换成'z',问经过一次转换之后,字典序最小的字符串s为多少.注意“exactly one non-empty substring”这就意味着全'a'串也要变,即字符串"aaa",替换其中的字母(会使得字典序比原来大),但又要使字典…
题意: Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game. Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will consis…
排列组合题 题意 用m种颜色的彩球装点n层的圣诞树.圣诞树的第i层恰由l[i]个彩球串成一行,且同一层内的相邻彩球颜色不同,同时相邻两层所使用彩球的颜色集合不同.求有多少种装点方案,答案对p取模. 只要任一位置上的彩球颜色不同,就算作不同的方案. 1 <= n,m <= 10^6, 2 <= p <= 10^9, 1 <= l[i] <= 5000, Σl[i] <= 10^7 若只考虑一层,就是bzoj1008的越狱,但是要考虑上下两层不同,卒. 考虑只在一层中…
Chocolate Bar 题意: 有一个n*m(1<= n,m<=30)的矩形巧克力,每次能横向或者是纵向切,且每次切的花费为所切边长的平方,问你最后得到k个单位巧克力( k <= min(n*m,50) )的最小花费是多少? 思路: 数据规模不大,但是贪心不能得到最优解,很自然想到了dp;里面涉及到行的减少和列的减少,在dp[][]表示中必定要以行数和列数作为dp的含义,但是好像这还不够,如果单单只是一个二维的dp[][]那这个表示的是取了(或者还需)几个单位巧克力呢? ==>…
Description 题库链接 求 \[C_n^m \mod p\] \(1\leq m\leq n\leq 10^{18},2\leq p\leq 1000000\) Solution 一般的 \(Lucas\) 是在模数 \(p\) 是质数的条件下适用的.我们来考虑 \(p\) 不是质数的条件. 我们对 \(p\) 进行唯一分解,记 \(p=p_1^{k_1}p_2^{k_2}\cdots p_q^{k_q}\) ,由于形同 \(p_i^{k_i}\) 的部分是互质的,显然我们可以用 \(…
题目链接 ->扩展Lucas //求C_n^k%m #include <cstdio> typedef long long LL; LL FP(LL x,LL k,LL p) { LL t=1ll; for(; k; k>>=1,x=x*x%p) if(k&1) t=t*x%p; return t; } void Exgcd(LL a,LL b,LL &x,LL &y) { if(!b) x=1ll, y=0ll; else Exgcd(b,a%b,y…
E. Let's Go Rolling! time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assu…
题目本身上手并不难,字符串处理+简单的排序.要注意的地方是浮点数的处理. 依据计算机中浮点数的表示原理,在实际编程的过程中即使用一个确定的整数(假设是1)给一个浮点变量赋值 在查看变量时会发现实际存储的值是0.99999…….可以注意到在使用原来的EPX*k时也有可能出现这样的情况,本来是准确值应该是100,浮点运算却会得到 99.999…… 由于k只有两位小数,因此一个整数乘上k,最多还是只有两位 我们令 新的经验new_epx=epx*k+0.001 当然可以用任何比0.01小的数,都能在不…
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer n is decided first. Both Koyomi a…
题目传送门 传送门I 传送门II 传送门III 题目大意 给定一个网络.网络分为$A$,$B$两个部分,每边各有$n$个点.对于$A_{i} \ (1\leqslant i < n)$会向$A_{i + 1}$连一条容量为$x_{i}$的有向边,对于$B_{i} \ (1\leqslant i < n)$会向$B_{i + 1}$连一条容量为$y_{i}$的有向边.$A$和$B$之间有$m$条边,起点为$A_{u_{i}}$,终点为$B_{v_{i}}$,容量为$w_{i}$的有向边.要求支持…
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino's makeshift residence. The space is represented by a rectangular grid of n × m cells, arranged into n…
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii-chan! With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewher…
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather long lif…
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes. A string is 1-palindrome if and only if it reads the same backward as f…
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c). Over time the stars twinkle. At moment 0 the i-th…
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The secon…
Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other. The boys decided to h…
n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-n…
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one.. There is a glob pattern in the statements (a string consis…
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules…
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum_{i = 1}^{n} a_{i} \leqslant K$的最大正整数$d$. 整理一下可以得到条件是$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil \leqslant K + \sum_{i = 1}^{n} a_{i}$…
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo…
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do this,…
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added…