2102: [Usaco2010 Dec]The Trough Game
2102: [Usaco2010 Dec]The Trough Game
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 117 Solved: 84
Description
Farmer John and Bessie are playing games again. This one has to do with troughs of water. Farmer John has hidden N (1 <= N <= 20) troughs behind the barn, and has filled some of them with food. Bessie has asked M (1 <= M <= 100) questions of the form, "How many troughs from this list (which she recites) are filled?". Bessie needs your help to deduce which troughs are actually filled. Consider an example with four troughs where Bessie has asked these questions (and received the indicated answers): 1) "How many of these troughs are filled: trough 1" --> 1 trough is filled 2) "How many of these troughs are filled: troughs 2 and 3" --> 1 trough is filled 3) "How many of these troughs are filled: troughs 1 and 4" --> 1 trough is filled 4) "How many of these troughs are filled: troughs 3 and 4" --> 1 trough is filled From question 1, we know trough 1 is filled. From question 3, we then know trough 4 is empty. From question 4, we then know that trough 3 is filled. From question 2, we then know that trough 2 is empty. 求N位二进制数X,使得给定的M个数,满足X and Bi=Ci ,Bi ci分别是读入的两个数
Input
* Line 1: Two space-separated integers: N and M * Lines 2..M+1: A subset of troughs, specified as a sequence of contiguous N 0's and 1's, followed by a single integer that is the number of troughs in the specified subset that are filled.
Output
* Line 1: A single line with: * The string "IMPOSSIBLE" if there is no possible set of filled troughs compatible with Farmer John's answers. * The string "NOT UNIQUE" if Bessie cannot determine from the given data exactly what troughs are filled. * Otherwise, a sequence of contiguous N 0's and 1's specifying which troughs are filled.
Sample Input
4 4 1000 1 0110 1 1001 1 0011 1
Sample Output
1010
HINT
Source
题解:一上来居然没有别的想法——只有暴力。。。然后写了个纯粹的二进制穷举,然后,然后,然后,居然AC了?!?!44ms也是醉大了= =
1 type
2 point=^node;
3 node=record
4 g:longint;
5 next:point;
6 end;
7 var
8 i,j,k,l,m,n,t:longint;
9 a:array[0..10000] of point;
10 b,c,d:array[0..10000] of longint;
11 c1,c2:char;
12 procedure add(x,y:longint);inline;
13 var p:point;
14 begin
15 new(p);p^.g:=y;
16 p^.next:=a[x];a[x]:=p;
17 end;
18 procedure dfs(x:longint);inline;
19 var i,j,k,l:longint;p:point;
20 begin
21 if x>n then
22 begin
23 for i:=1 to m do if b[i]>0 then exit;
24 if t=0 then
25 begin
26 for i:=1 to n do d[i]:=c[i];
27 t:=1;
28 end
29 else
30 begin
31 writeln('NOT UNIQUE');
32 halt;
33 end;
34 end
35 else
36 begin
37 p:=a[x];l:=0;
38 while p<>nil do
39 begin
40 if b[p^.g]=0 then
41 begin
42 l:=1;
43 break;
44 end;
45 p:=p^.next;
46 end;
47 if l=0 then
48 begin
49 p:=a[x];
50 while p<>nil do
51 begin
52 dec(b[p^.g]);
53 p:=p^.next;
54 end;
55 c[x]:=1;
56 dfs(x+1);
57 p:=a[x];
58 while p<>nil do
59 begin
60 inc(b[p^.g]);
61 p:=p^.next;
62 end;
63 end;
64 c[x]:=0;
65 dfs(x+1);
66 end;
67 end;
68
69 begin
70 readln(n,m);
71 for i:=1 to m do a[i]:=nil;
72 for i:=1 to m do
73 begin
74 for j:=1 to n do
75 begin
76 read(c1);
77 if c1='1' then add(j,i);
78 end;
79 readln(b[i]);
80 end;
81 t:=0;
82 dfs(1);
83 IF t=0 then write('IMPOSSIBLE') else for i:=1 to n do write(d[i]);
84 writeln;
85 readln;
86 end.
- 腾讯云发布企业级微服务中间件TSF,助企业构建亿级互联网应用架构
- java学习:字符串比较“==”与“equals”的差异及与c#的区别
- 纯C语言程序员写的编程新手入门基础小游戏之最炫酷推箱子
- Oracle BIEE (Business Intelligence) 11g 11.1.1.6.0 学习(2)RPD资料档案库创建
- Oracle BIEE (Business Intelligence) 11g 11.1.1.6.0 学习(3)创建一个简单的分析
- 请查收!这里有一封信鸽传给您的信
- Oracle BIEE (Business Intelligence) 11g 11.1.1.6.0 学习(4)创建多维钻取分析
- silverlight:RadMaskedTextBox设置MaskType="Numeric"及Mask="n"时的一个bug
- 微信里面最神秘的功能,你知道吗?
- 以大数据之名,变身!——In big data we trust
- 90%家长都不知道关于少儿编程的这些疑题!
- 常用SQL语句和语法汇总
- Python学习笔记1——斐波那契数列
- 视觉传感器几大技术要点详解!
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- OSCache页面缓存的使用
- 静态化技术Freemarker
- 递归的编译优化(1)
- JAVA高并发处理------多线程
- 安卓笔记一
- 这样使用df和du命令更完美
- 批处理中的IF详解
- 来,我们一起打造一款代码命名工具
- HTML转PDF工具Wkhtmltopdf安装使用
- 【Vue.js】Vue.js组件库Element中的时间选择器、日期选择器、日期时间选择器和颜色选择器
- 【Vue.js】Vue.js的Chrome浏览器开发插件DevTools的安装步骤
- 训练提速60%!只需5行代码,PyTorch 1.6即将原生支持自动混合精度训练。
- TensorFlow 模型剪枝
- 机器人如何使用 RRT 进行路径规划?
- 高效 PyTorch:6个训练Tips