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 ...
随机推荐
- 关于Java IM的一点资料
微信是腾讯采用自己开发的协议做的,其他市面上很多产品大都是采用XMPP协议,包括米聊在内之前也是这样子. 采用XMPP协议,服务端可以采用OpenFire搭建,客户端有个开源的叫asmack的东西,g ...
- mongo数据库使用小结
db.userId5555.aggregate({$unwind:"$tcjl"},{$match:{"_id":"0e549864-2a56-43c ...
- java 优化
代码优化,一个很重要的课题.可能有些人觉得没用,一些细小的地方有什么好修改的,改与不改对于代码的运行效率有什么影响呢?这个问题我是这么考虑的,就像大海里面的鲸鱼一样,它吃一条小虾米有用吗?没用,但是, ...
- PyQt5创建第一个窗体(正规套路)
一.Pyqt5 创建第一个窗体 很多人写窗体程序都是直接敲代码,不使用设计器,我个人不是很赞成这种做法.使用设计器的好处是直观.维护方便,尤其开发复杂窗体的效率高. 但是每次修改ui文件后,需要重新生 ...
- WPF后台访问XAML元素
当我们需要从后台访问xaml文件时,我们可以通过这样的方式来操作: private void button1_Click(object sender, RoutedEventArgs e) { Sys ...
- Quartz1.8.5例子(四)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
- JSP中两种模式的总结
运用JSP/Servlet实现的Web动态交互,主要采用: 模式一:JSP+JavaBean 链接:http://wxmimperio.coding.io/?p=155 模式二;JSP+Servlet ...
- 利用Anaconda安装python后,如何安装opencv-python
利用Anaconda安装python后,想要安装opencv-python,但发现利用opencv-python的官方教程,没法实现opencv的安装 还好看到了另外一篇博客的方法,试一下,果然凑效 ...
- 日期相关---SimpleDateFormat的setLenient(true/false)-----自动计算日期
有时候我们需要判断用户的日期格式是否正确, 虽然绝大多数会在前台处理,但是也有需要从文件流读入的情况,如果日期不合格就需要抛异常,这时候就需要禁止SimpleDateFormat的自动计算功能. 这时 ...
- wcf安全
http://www.cnblogs.com/artech/archive/2011/07/07/customauthorization01.html 安全 http://www.cnblogs.co ...