填坑系列(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的更多相关文章

  1. UVA1607 Gates 与非门电路 (二分)

    题意:给你一个按发生时间的序列,表示与非门电路的输入,一开始全部输入是x,现在要改成尽量少的x,实现相同的功能. 题解:电路功能只有4中0,1,x,非x.那么如果一开始x改变了,输出结果不变,那么说明 ...

  2. xor和gates的专杀脚本

    前段时间的一次样本,需要给出专杀,应急中遇到的是linux中比较常见的两个家族gates和xor. 首先是xor的专杀脚本,xor样本查杀的时候需要注意的是样本的主进程和子进程相互保护(详见之前的xo ...

  3. [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 ...

  4. 【转】Memory gates checking failed because the free memory***解决办法

    Issue: Vault users cannot connect. VLOGS show the following error: Memory gates checking failed beca ...

  5. Uva - 1607 - Gates

    题目理解麻烦,估计提交量少(总共只有32个人...)也是因为题目比较麻烦,看起来像物理题,实际理解了还可以.整个电路的功能就4种,先判断x=0和x=1的输出是否相同,吐过相同,而整个电路是常熟,随便输 ...

  6. [转] 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 ...

  7. [bug]WCF 内存入口检查失败 Memory gates checking failed

    bug描述 异常信息:内存入口检查失败,因为可用内存(xxx 字节)少于总内存的 xx%.因此,该服务不可用于传入的请求.若要解决此问题,请减少计算机上的负载,或调整 serviceHostingEn ...

  8. B. Fafa and the Gates

    http://codeforces.com/problemset/problem/935/B Two neighboring kingdoms decided to build a wall betw ...

  9. Fafa and the Gates(模拟)

    Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens ...

随机推荐

  1. thinkphp关联查询(多表查询)

    1.Table方法:定义要操作的数据表名称,可以动态改变当前操作的数据表名称,需要写数据表的全名,包含前缀,可以使用别名, 例如: $Model->Table('think_user user' ...

  2. NoSql之Redis使用(一)

    一.安装 1.下载安装包: 官方网站:redis.io 官方推荐windows版本:https://github.com/MSOpenTech/redis 2:下载压缩包,解压后如下 redis-se ...

  3. Eclipse debug调试

    Eclipse debug调试: F5:跳入方法F6:向下逐行调试F7:跳出方法F8:直接跳转到下一个断点

  4. php 扩展编译linux

    进入扩展库目录:$cd phpredis-master 需要root权限执行 执行:$ phpize 执行:$ ./configure 执行:$ make 执行:$ make install   编译 ...

  5. C# Json反序列化处理

    最近换工作了 从客户端转到Web端 第一个任务就是去别人的页面上抓取数据 用到的是JSON 因为他们网站json的格式有点怪 所以 就在JSON反序列化上面 花了一点时间 首先用到的工具是http:/ ...

  6. UFLDL教程之(三)PCA and Whitening exercise

    Exercise:PCA and Whitening 第0步:数据准备 UFLDL下载的文件中,包含数据集IMAGES_RAW,它是一个512*512*10的矩阵,也就是10幅512*512的图像 ( ...

  7. [操作系统]iOS6与iOS7屏幕适配技巧

    一.没有包装任何 导航控制器 或者 UITabBarController 1.控制器的view是UIScrollView\UITableView\UICollectionView时(控制器是UITab ...

  8. Bomb Game

    hdu3622:http://acm.hdu.edu.cn/showproblem.php?pid=3622 题意:你有n次,每次你可以在平面上放置一个点,并且每一次都会有两个位置可以选,每一次只能选 ...

  9. 【Windows 8】pid为4的system进程占用80端口的解决办法

    因为Apache无法启动的原因,用netstat命令查看了一下80端口是否被占用了,如下: C:\Users\Maple>netstat -ano | findstr TCP LISTENING ...

  10. CSS3 :nth-of-type() 选择器

    可以设定第几个元素的样式 案例 css .qrcode img { margin-top: 30px; } .qrcode p:nth-of-type(1) { /*第一个p*/ font-size: ...