UVa1607 poj1435 UVaLive1686 Gates
填坑系列(p.246)
由函数连续性得满足二分性
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream> using namespace std; void setIO(const string& s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template<typename Q> Q read(Q& x) {
static char c, f;
for(f = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
if(f) x = -x;
return x;
}
template<typename Q> Q read() {
static Q x; read(x); return x;
} const int N = + ; int n, m;
struct Gates {
int a, b, o;
}gates[N]; int output(int k) {
for(int i = ; i <= m; i++) {
int a = gates[i].a;
int b = gates[i].b;
int va = a < ? -a > k : gates[a].o;
int vb = b < ? -b > k : gates[b].o;
gates[i].o = !(va && vb);
}
return gates[m].o;
} int solve(int vn) {
int L = , R = n;
while(L < R) {
int mid = L + (R - L) / ;
if(output(mid) == vn) R = mid; else L = mid + ;
}
return L;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif int T; scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++) {
scanf("%d%d", &gates[i].a, &gates[i].b);
}
int v0 = output(), vn = output(n);
if(v0 == vn) for(int i = ; i <= n; i++) putchar('');
else {
int p = solve(vn);
for(int i = ; i < p; i++) putchar('');
putchar('x');
for(int i = p + ; i <= n; i++) putchar('');
}
puts("");
} return ;
}
UVa1607 poj1435 UVaLive1686 Gates的更多相关文章
- UVA1607 Gates 与非门电路 (二分)
题意:给你一个按发生时间的序列,表示与非门电路的输入,一开始全部输入是x,现在要改成尽量少的x,实现相同的功能. 题解:电路功能只有4中0,1,x,非x.那么如果一开始x改变了,输出结果不变,那么说明 ...
- xor和gates的专杀脚本
前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor. 首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xo ...
- [Locked] Walls and Gates
Walls and Gates You are given a m x n 2D grid initialized with these three possible values. -1 - A w ...
- 【转】Memory gates checking failed because the free memory***解决办法
Issue: Vault users cannot connect. VLOGS show the following error: Memory gates checking failed beca ...
- Uva - 1607 - Gates
题目理解麻烦,估计提交量少(总共只有32个人...)也是因为题目比较麻烦,看起来像物理题,实际理解了还可以.整个电路的功能就4种,先判断x=0和x=1的输出是否相同,吐过相同,而整个电路是常熟,随便输 ...
- [转] How Bill Gates read books
Bill Gates is one of the most famous figures in the business world. He is one of the richest men in ...
- [bug]WCF 内存入口检查失败 Memory gates checking failed
bug描述 异常信息:内存入口检查失败,因为可用内存(xxx 字节)少于总内存的 xx%.因此,该服务不可用于传入的请求.若要解决此问题,请减少计算机上的负载,或调整 serviceHostingEn ...
- B. Fafa and the Gates
http://codeforces.com/problemset/problem/935/B Two neighboring kingdoms decided to build a wall betw ...
- Fafa and the Gates(模拟)
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens ...
随机推荐
- 自然数e为底数的指数函数的一个小运用
以自然数e为底数的指数函数: 半衰期: 倍增期:
- [LeetCode OJ] Word Search 深度优先搜索DFS
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...
- Linux的cat、more、less的区别
cat命令功能用于显示整个文件的内容单独使用没有翻页功能因此经常和more命令搭配使用,cat命令还有就是将数个文件合并成一个文件的功能. more命令功能:让画面在显示满一页时暂停,此时可按空格健继 ...
- android关于installLocation
以下内容主要参考自官网的描述. 从Android API-8开始,android允许你将应用程序安装到外部存储空间中去(比方:SD卡),你可以在AndroidManifest.xml中添加androi ...
- Setup FTP Server On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3
setsebool allow_ftpd_full_access onsetsebool -P ftp_home_dir on vsftpd (Very Secure File Transport P ...
- JavaScript 输入自动完成插件
作为web开发的一员,应该都不陌生,信息处理时,很多时候需要根据用户的输入实时反馈查询结果供其选择,这给了用户很好的人机交互体验,在各大门户网站上已经被使用的很成熟了,最近项目中用到此功能,网上有很多 ...
- js判断用户进入设备代码
var system ={ win : false, mac : false, xll : false }; //检测平台 var p = navigator.platform; system.win ...
- IS---InstallShield第二天
在Setup.rul中,新增OnBegin函数 STRING str1,spath,szApplicationPath,szApplicationCmdLine,szCmdLine;function ...
- [Linux]命令root与other切换
切换至root:sudo -i切换至other:su 用户名
- smarty 模板 数字自动添加
section: section的产生是为解决foreach的不足的,与foreach一样,它用于设计模板内的循环块,它较为复杂,可极大程序上满足程序需要,所以在程序中我习惯使用它而不使用foreac ...