填坑系列(p.246)

由函数连续性得满足二分性

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<algorithm>
 5 #include<iostream>
 6
 7 using namespace std;
 8
 9 void setIO(const string& s) {
10     freopen((s + ".in").c_str(), "r", stdin);
11     freopen((s + ".out").c_str(), "w", stdout);
12 }
13 template<typename Q> Q read(Q& x) {
14     static char c, f;
15     for(f = 0; c = getchar(), !isdigit(c); ) if(c == '-') f = 1;
16     for(x = 0; isdigit(c); c = getchar()) x = x * 10 + c - '0';
17     if(f) x = -x;
18     return x;
19 }
20 template<typename Q> Q read() {
21     static Q x; read(x); return x;
22 }
23
24 const int N = 200000 + 5;
25
26 int n, m;
27 struct Gates {
28     int a, b, o;
29 }gates[N];
30
31 int output(int k) {
32     for(int i = 1; i <= m; i++) {
33         int a = gates[i].a;
34         int b = gates[i].b;
35         int va = a < 0 ? -a > k : gates[a].o;
36         int vb = b < 0 ? -b > k : gates[b].o;
37         gates[i].o = !(va && vb);
38     }
39     return gates[m].o;
40 }
41
42 int solve(int vn) {
43     int L = 1, R = n;
44     while(L < R) {
45         int mid = L + (R - L) / 2;
46         if(output(mid) == vn) R = mid; else L = mid + 1;
47     }
48     return L;
49 }
50
51 int main() {
52 #ifdef DEBUG
53     freopen("in.txt", "r", stdin);
54     freopen("out.txt", "w", stdout);
55 #endif
56
57     int T; scanf("%d", &T);
58     while(T--) {
59         scanf("%d%d", &n, &m);
60         for(int i = 1; i <= m; i++) {
61             scanf("%d%d", &gates[i].a, &gates[i].b);
62         }
63         int v0 = output(0), vn = output(n);
64         if(v0 == vn) for(int i = 1; i <= n; i++) putchar('0');
65         else {
66             int p = solve(vn);
67             for(int i = 1; i < p; i++) putchar('0');
68             putchar('x');
69             for(int i = p + 1; i <= n; i++) putchar('1');
70         }
71         puts("");
72     }
73
74
75     return 0;
76 }

View Code

转载于:https://www.cnblogs.com/showson/p/5090642.html

UVa1607 poj1435 UVaLive1686 Gates相关推荐

  1. WCF 内存入口检查失败 Memory gates checking failed

    WCF 内存入口检查失败 Memory gates checking failed   异常信息:内存入口检查失败,因为可用内存(xxx 字节)少于总内存的 xx%.因此,该服务不可用于传入的请求.若 ...

  2. xor和gates的专杀脚本

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

  3. 我为Bill Gates熬夜加班的那个晚上

    现在是凌晨5点,距离Bill Gates的演示会议还有5个小时. 我的眼睛又红又肿,有点儿神志不清. 我已经有快24小时没有睡觉了, 我刚刚重新编译了代码,它看起来已经可以工作了. 给Bill Gat ...

  4. Towards Binary-Valued Gates for Robust LSTM Training

    Towards Binary-Valued Gates for Robust LSTM Training 一.首先给出LSTM公式 it=σ(Wxixt+Whiht−1+bi)it=σ(Wxixt+W ...

  5. Make a mark of Gates

    转贴,Make a mark of Gates: 连线杂志:盖茨53年人生大事记 导语:<连线>杂志近日撰文称,微软创始人兼董事会主席比尔·盖茨(Bill Gates)将于7月正式退出微软 ...

  6. Unix.Trojan.DDoS_XOR-1、Linux.Trojan.Agent(Linux.BackDoor.Gates.5)木马清理

    一.现象 Linux服务器被黑, 向外疯狂发包,造成网络瘫痪.nload显示100Mbit/s.(nload统计流量软件) 二.木马扫描 1.ClamAV介绍 ClamAV是一个在命令行下查毒软件,因 ...

  7. 万卷书 - 欧洲的门户 [The Gates of Europe]

    欧洲门户 [删减版] 乌克兰的历史 作者:谢尔盖-普洛克希 概要 <The Gates of Europe>(2015年)对乌克兰的历史进行了深入的阐述.这个国家横跨欧亚之间,由于这一独特 ...

  8. 万卷书 - 欧洲的门户[The Gates of Europe]

    欧洲门户 Wu克蓝的历史 作者:谢尔盖-普洛克希 概要 <The Gates of Europe>(2015年)对Wu克蓝的历史进行了深入的阐述.这个国家横跨欧亚之间,由于这一独特的地理位 ...

  9. Debut of Hyper-V, departure of Gates usher[引导,展示,招待员] in new era for Microsoft

    Debut of Hyper-V, departure of Gates usher[引导,展示,招待员] in new era for Microsoft Posted by Paula Roone ...

最新文章

  1. 判断接收的数据中是否有中文
  2. 2020前三季度各省市人均收入来了!看看你的家乡排第几?
  3. linux 内核配置raid,在 Linux VM 上配置软件 RAID - Azure Virtual Machines | Microsoft Docs
  4. 若川邀你进 源码共读 群~长期交流学习
  5. idea使用junit测试_在JUnit测试中使用Builder模式
  6. java file 堵塞_单元测试最终在Java 6中阻塞
  7. pp2使用需要java_新GRE模考软件POWERPREP2安装和使用说明(图解)
  8. 使用JavaScript下进行iframe的DOM操作(考虑浏览器兼容性)
  9. 代码快速“检”“修”不是梦,阿里云MaxCompute Studio 2.9.0 新版本发布
  10. Google日历服务快捷、简便
  11. python的paramiko模块
  12. 【DL小结5】Transformer模型与self attention
  13. 2008-8-26~2008-9-4 出差报告
  14. html js动态时间轴,jQuery时间轴插件timeline.js
  15. Linux服务篇之远程访问及控制SSH
  16. vue中根据汉字生成拼音
  17. Cent OS几个好玩的命令
  18. 郭炜实用Python程序设计慕课:chapter13面向对象程序设计
  19. 腾讯研究院夹缝中生存 35万年薪难求才
  20. 腾讯与阅文技术合作 微服务框架Tars再添PHP

热门文章

  1. hive建立内部表映射hbase_快手 HBase 在千亿级用户特征数据分析中的应用与实践...
  2. 盘点八个程序员必备的代码编辑器
  3. 常用的几个JavaScript调试技巧
  4. mysql001创建数据库
  5. C++ - 进阶 1002
  6. 写在2021: 值得关注/学习的前端框架和工具库
  7. (送书和红包)快人一步,掌握前端函数式编程
  8. 调试 SharePoint 解决方案
  9. Android 应用安全性改进: 全面助力打造 零漏洞 应用
  10. Kali安装magescan评估工具