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 ...
随机推荐
- php 连接mysql数据库并显示数据 实例 转载
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- mount的艺术
在阅读本文之前,我假设你已经对Linux系统下的硬盘.光盘的设备命令规则有所了解,比如sda和sda1的关系,以及hda.sda.fd.cdrom等设备. === 1 我把U盘插到USB口上了,下一步 ...
- 在js脚本里计算多个小数的加法问题
当在js脚本里计算多个小数的加法时,算得的结果往往会自动取整,这时候我们就应该加入以下代码: function toDecimal(x) { var val = Number(x); if (!isN ...
- javascript判断设备类型-手机(mobile)、安卓(android)、电脑(pc)、其他(ipad/iPod/Windows)等
使用device.js检测设备并实现不同设备展示不同网页 html代码: <!doctype html> <html> <head> <meta charse ...
- js 中的流程控制-循环(for)语句
for语句: <script> /* for(exp1;exp2;exp3){ 循环体; } exp1:无条件的执行第一个表达式 exp2:判断是否能执行循环体的条伯 exp3:做增量的操 ...
- 一些static_cast const_cast
static_cast:干杂活的,那三个都有各自的专有用途,那三个不做的都由这个转型符来做,只要它能做的,用C语法的强制类型转换运算符也一定能够完成:但话又说回来了,C强制类型转换能做的,它可不一定都 ...
- 设置(TableViewController)通用框架
本文学习于传播播客.李明杰老师.感谢
- 1.1机器学习基础-python深度机器学习
参考彭亮老师的视频教程:转载请注明出处及彭亮老师原创 视频教程: http://pan.baidu.com/s/1kVNe5EJ 1. 课程介绍 2. 机器学习 (Machine Learning, ...
- 手写js面向对象选项卡插件
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- iOS:使用导航栏
要求使用ARC // // main.m // Hello // // Created by lishujun on 14-8-28. // Copyright (c) 2014年 lishujun. ...