Uva - 1607 - Gates
题目理解麻烦,估计提交量少(总共只有32个人。。。)也是因为题目比较麻烦,看起来像物理题,实际理解了还可以。整个电路的功能就4种,先判断x=0和x=1的输出是否相同,吐过相同,而整个电路是常熟,随便输出;如果不同,,而二分1的个数继续测试。
AC代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cctype> #include <cstring> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <algorithm> #include <stack> #include <queue> #include <bitset> #include <cassert> #include <cmath> #include <functional> using namespace std; const int maxm = 200005; int n, m; struct Gates { int a, b, o; }gates[maxm]; // k个0输入,即000..0111...1这种情况的输出 int output(int k) { for (int i = 1; i <= m; i++) { int a = gates[i].a; int b = gates[i].b; int va = a < 0 ? -a > k : gates[a].o; int vb = b < 0 ? -b > k : gates[b].o; gates[i].o = !(va && vb); } return gates[m].o; } int solve(int vn) { int L = 1, R = n; while (L < R) { int mid = L + (R - L) / 2; // 二分1的个数 if (output(mid) == vn) { R = mid; } else { L = mid + 1; } } return L; } int main() { ios::sync_with_stdio(false); int T; cin >> T; while (T--) { cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> gates[i].a >> gates[i].b; } int v0 = output(0); int vn = output(n); if (v0 == vn) { // 相同,那么整个电路就是常数 for (int i = 1; i <= n; i++) { cout << "0"; } } else { int x = solve(vn); for (int i = 1; i < x; i++) { cout << "0"; } cout << "x"; for (int i = x + 1; i <= n; i++) { cout << "1"; } } cout << endl; } return 0; }
Uva - 1607 - Gates的更多相关文章
- UVa 1607 (二分) Gates
这道题真的有点“神”啊.= ̄ω ̄= 因为输入都是x,所以整个电路的功能一共就四种:0, 1, x,!x 所以就确定了这样一个事实:如果电路的输出是常数,那么所有的输入都可以优化成常数. 否则,只需要将 ...
- 紫书 例题8-14 UVa 1607 (二分)
题意非常难理解-- #include<cstdio> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namesp ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
随机推荐
- 初识Redis系列之二:安装及简单使用
仅介绍windows下的安装 一:下载地址:https://github.com/MSOpenTech/redis/releases. Redis 支持 32 位和 64 位.这个需要根据你系统平台的 ...
- 排序算法的C语言实现(上 比较类排序:插入排序、快速排序与归并排序)
总述:排序是指将元素集合按规定的顺序排列.通常有两种排序方法:升序排列和降序排列.例如,如整数集{6,8,9,5}进行升序排列,结果为{5,6,8,9},对其进行降序排列结果为{9,8,6,5}.虽然 ...
- 【kmp】 剪花布条 HDU - 2087
[题意概述] [解题思路] 从左往右找,看有几个匹配的字符串,但要注意例如 aaaaaa aa的输出是3 而不是5,可以这样理解:画布需要减去,一旦减去也就没有了的 [AC] #include< ...
- Python3 条件控制
if 语句 Python中if语句的一般形式如下所示: if condition_1: statement_block_1 elif condition_2: statement_block_2 el ...
- 制定一个apk路径 然后跳出安装界面
制定一个apk的路径 然后跳出界面让用户选择是否安装 我们系统有一个写好的Activity来协助我们完成这一功能 我们来看看它的清单文件 <?xml version="1.0" ...
- [BBS]搭建开源论坛之Jforum搭配开源CKEDITOR
本文作者:sushengmiyan 本文地址:http://blog.csdn.net/sushengmiyan/article/details/47946065 使用默认的编辑器的时候,格式都无法保 ...
- 百度编辑器UEditor常用设置函数
最近在研究UEditor的使用,下面是附上传送门: 这是API文档http://ueditor.baidu.com/doc/ 这是下载地址http://ueditor.baidu.com/websit ...
- 可能是CAP理论的最好解释
一篇非常精彩的解释CAP理论的文章,翻译水平有限,不准确之处请参考原文,还请见谅. Chapter 1: "Remembrance Inc" Your new venture : ...
- 1.Cocos2d-x-3.2编写3d打飞机,粒子管理器代码
Cocos2d-x中的一个单例效果: #ifndef __Moon3d__ParticleManager__ #define __Moon3d__ParticleManager__ #inclu ...
- 对 jiffies 溢出、回绕及 time_after 宏的理解
原文如下: 关于jiffies变量: 全局变量jiffies用来记录自启动以来产生的节拍的总数.系统启动时会将该变量初始化为0,此后,每当时钟中断产生时就会增加该变量的值.jiffies和另外 ...