CodeForces 778B - Bitwise Formula】的更多相关文章

题意: 选择一个 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位二进制数表示,这n个数的value将以两种格式中的一种给出 1.变量名, 空格, ":=", 空格, 一个正好m位的二进制数 eg(m = 3):   a := 101 2.变量名, 空格, ":=", 空格, 第一个变量, 空格, 位运算符(AND,OR,XOR), 空格, 第二个变量 每一个变量都是前面被定义过的变量或者用 '?'表示 e…
位运算,枚举. 按按分开计算,枚举$?$是$0$还是$1$,分别计算出$sum$,然后就可以知道该位需要填$1$还是$0$了. #include<map> #include<set> #include<ctime> #include<cmath> #include<queue> #include<string> #include<vector> #include<cstdio> #include<cstr…
[题目链接]:http://codeforces.com/contest/779/problem/E [题意] 给你n个长度为m的二进制数 (有一些是通过位运算操作两个数的形式给出); 然后有一个未知数字,用符号'?'表示; (所有的数字都是长度为m的二进制数); 然后让你确定这个'?'使得n个数字的和最大.最小; [题解] 模拟题; 会有嵌套的情况: 即 a=x & y b=a&? 类似这样. 所以在算b之前,先把a的值确定下来; 明白了怎么算之后; 枚举那个未知数字的m位的每一位; 每…
按位考虑,每个变量最终的赋值要么是必为0,要么必为1,要么和所选定的数相同,记为2,要么和所选定的数相反,记为3,一共就这四种情况. 可以预处理出来一个真值表,然后从前往后推导出每个变量的赋值. 然后从高位到低位考虑,如果某一位,对于所有变量而言,2的数量大于等于3的数量,就把所选定的数的该位记为0,否则记为1,就能满足和最小.反之就能满足和最大. #include<cstdio> #include<string> #include<iostream> #include…
题意: 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…
Codeforces 题面传送门 & 洛谷题面传送门 Yet another immortal D1+D2 I %%%%%% 首先直接统计肯定是非常不容易的,不过注意到这个 \(k\) 非常小,因此考虑对这个 \(k\) 做点文章.我们考虑每个数被执行了多少次 \(-1\) 操作,设第 \(i\) 个数被执行了 \(b_i\) 次 \(-1\) 操作,那么最终的结果就是 \((a_1-b_1)\oplus(a_2-b_2)\oplus\cdots\oplus(a_n-b_n)\).然后就是比较神…
题意 给定三个整数 \(n,k,c\) 和一个长度为 \(n\) 的序列 \(a\),保证 \(a_i\) 互不相同.可以操作 \(k\) 次,每次随机选择一个 \(a_i\) 变成 \(a_i-1\).问最后的序列异或和为 \(0,\cdots 2^{c}-1\) 的概率. \(\texttt{Data Range:}k,c\leq 16,k\leq a_i\leq 2^c-1,n\leq 2^{c}-k\) 题解 先来看一个显而易见的结论:对于 \(x\leq 2^c-1\),本质不同的 \…
A题卡壳了,往离线倒着加那方面想了会儿,后来才发现方向错了,二十多分钟才过掉,过了B后做D,想法好像有点问题,最后只过两题,掉分了,差一点回紫. AC:AB Rank:173 Rating:2227-23->2204 A.String Game 题目大意:给出字符串A和B,保证B是A的子序列,给出一个长度为A串长度的排列,问按排列的顺序删掉A串中字符,最多删几个使得B任然是A的子序列.(A串长度<=200,000) 思路:发现答案满足单调性,二分删几个,O(n)check一下B还是不是A的子序…
哎,今天第一次打div1 感觉头脑很不清醒... 看到第一题就蒙了,想了好久,怎么乱dp,倒过来插之类的...突然发现不就是一道sb二分吗.....sb二分看了二十分钟........ 然后第二题看了一下,感觉太码农了不可做,然后就cd逛一逛. 突然觉得c可做,就做了一下,交上去wa了,发现有情况没考虑. 这下又滚回了b,结果又没写完...... gg  2040 -83 ->1957 -----------------------------------------------我似分割线啊 A…
A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In Berland each high school student is characterized by academic performance — integer value between 1 and 5. In hig…
2017.2.26 CF D2 402 这次状态还算能忍吧……一路不紧不慢切了前ABC(不紧不慢已经是在作死了),卡在D,然后跑去看E和F——卧槽怎么还有F,早知道前面做快点了…… F看了看,不会,弃 E看了看,不会,弃 D看了看,不会……没法再弃了.想了好久发现可以二分答案(浪费30min) 过了D以后去看F,发现果然还是不会(浪费20min) 之后看E,思路跑偏浪费20min+ 此时时间还剩大约20min,终于想到了E可能是正解的做法,开始拼手速,各种调试,终于调过了样例,而时间只剩10s了…
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…
F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树,满足只有一个点的权值最小,然后除开这个点,每个点都有一个权值比它更小的点与之相邻. 然后要求你重构这颗树,满足点权及边权和最小. 点权计算方法: au = au*num(num为与之相邻边的个数); 边权计算方法: e{u,v},we = dis(u,v)*min(au,av)  (dis(u,v…
做这题的时候发现题解里有提到\(generalizations\ of\ Cayley's\ formula\)的,当场懵逼,Wikipedia里也就带到了一下,没有解释怎么来的,然后下面贴了篇论文. 大概就是\(n\)个点\(k\)个联通块的森林,\(1,2,\cdots,k\)属于不同的联通块,这样不同的方案数共有\(k\cdot n^{n-k-1}\)种. 我自己用\(Prüfer\)序列脑补了半天没搞懂怎么来的,始终觉得感性理解是\(n^{n-k}\),然后就去看了下那个证明. 用\(F…
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 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<vector> #define MAXN 100000+10 #define ll long long #define pb push_back #define ft first #define sc second #define mp make_pair using…
题目链接 ->扩展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…
大意: 给定序列$a$, 给定整数$x$. 两种操作(1)单点修改 (2)给定区间$[l,r]$,求有多少子区间满足位或和不少于$x$. 假设不带修改. 固定右端点, 合法区间关于左端点单调的. 可以预处理出最近的合法的左端点位置.那么每次询问答案就为$\sum\limits_{\substack{pre[i]\ge l\\ l \le i\le r}}(pre[i]-l+1)$. 用二维数点的方法处理即可. 带修改的话, 关键是要注意到或和最多改变$20$次, 线段树记录下来改变的位置, 暴力…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Victor adores the sets theory. Let us remind you that a set is a group of…
[codeforces 339]D. Xenia and Bit Operations 试题描述 Xenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better understand how they work, Xenia decided t…
C. Vanya and Label 题目链接:http://codeforces.com/contest/677/problem/C While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base…
Magic Formulas Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description People in the Tomskaya region like magic formulas very much. You can see some of them below. Imagine you are given a sequence of pos…
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully sub…
题目链接: http://codeforces.com/contest/703/problem/D D. Mishka and Interesting sum time limit per test 3.5 secondsmemory limit per test 256 megabytes 问题描述 Little Mishka enjoys programming. Since her birthday has just passed, her friends decided to prese…
题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 secondsmemory limit per test 256 megabytes 问题描述 You've got an array a, consisting of n integers a1, a2, ..., an. You are allowed to perform two operations on…
Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q queries and a multiset A, initially containing only integer…
题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a…
B. OR in Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/problem/B Description Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if eith…