博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How many people have ipad II(数学)
阅读量:7022 次
发布时间:2019-06-28

本文共 2940 字,大约阅读时间需要 9 分钟。

How many people have ipad II

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 174    Accepted Submission(s): 60

Problem Description
hh found more and more of his friends are having ipad IIs. One day when they get together, hh asked his five friends, "How many of you have ipad II now?"
"One!"
"Three!"
"Everyone!"
"Four!"
"Two!"
hh's friends knew each other. They were clear about the "how many" question, while the answers are different, so there must be some people telling lies.
One of hh's friends told him(hh):
number of people, who had ipad IIs, and lied, was no more than 1.
number of people, who didn't have ipad IIs, and told the truth, was no more than 2.
at least one people have ipad II.
Given the information, hh realized there may be one or two people having ipad IIs.
Now hh asks N people the "how many" question. These N friends answer one by one. Some tell the truth, some lie. What hh knows is:
1.number of people, who have ipad IIs, and lie, is no more than A.
2.number of people, who don't have ipad IIs, and tell the truth, is no more than B.
3.At least one people have ipad II.
How many ipad IIs do these N people have?
 

 

Input
The input begins with an integer T(1<=T<=100).
The next T blocks each indicates a case.
The first line of each case contain a number N(1<=N<=16) then N positive integers follow, integers won't be lager than N.
Then following two numbers A , B(0 <= A,B <= N).
 

 

Output
Output the number of people have ipad II.
There may be many answers, output them by increasing order. (separated by space)
Output "impossible" if that's impossible.
 

 

Sample Input
3 5 1 2 3 4 5 1 2 3 0 0 0 1 1 4 0 0 0 0 0 1
 

 

Sample Output
1 2 1 impossible
 

 

Author
NotOnlySuccess
 

 

Source
 

 

Recommend
lcy
 

 

 |  |  |

m为拥有ipad的人数,tr为说真话的人数,N - tr为说谎人数。

假设tr个说真话的人中有j个拥有ipad,得
1、拥有ipad但说谎的人数为m - j,且0 <= m - j <= A;
2、木有ipad但说真话的人数为tr - j,且0 <= tr - j <= B;
3、j的范围:0 <= j <= tr.
4、i的范围:0 <= m <= N.

此外,这题有一个让人极其无语之处,就是N的范围不是题中所说的那么小。。。

AC Code:

1 #include 
2 #include
3 4 using namespace std; 5 6 int N, A, B, T, a[50], ans[50], top; 7 8 bool Judge(int m) 9 {10 int tr = 0;11 for(int i = 0; i < N; i++)12 if(a[i] == m) tr++;13 for(int j = 0; j <= tr; ++j)14 {15 if(m - j >= 0 && m - j <= A && tr - j >= 0 && tr - j <= B) return true;16 }17 return false;18 }19 20 int main()21 {22 scanf("%d", &T);23 while(T--)24 {25 top = 0;26 scanf("%d", &N);27 for(int i = 0; i < N; i++)28 {29 scanf("%d", &a[i]);30 }31 scanf("%d %d", &A, &B);32 for(int i = 1; i <= N; i++)33 {34 if(Judge(i)) ans[top++] = i;35 }36 if(!top) puts("impossible");37 else38 {39 for(int i = 0; i < top - 1; i++) printf("%d ", ans[i]);40 printf("%d\n", ans[top - 1]);41 }42 }43 return 0;44 }

 

转载地址:http://ydbxl.baihongyu.com/

你可能感兴趣的文章
iOS 开发小技巧 (持续更新)
查看>>
安装redis
查看>>
CFileDialog用法
查看>>
基于代理和注解机制,实现消息重发(APP,SMS)效果
查看>>
你和高级工程师的差距在哪里?
查看>>
使用maven构建android项目
查看>>
自然语言处理-分词工具
查看>>
Linux配置运行环境
查看>>
敏捷开发的特点
查看>>
zipfile
查看>>
线程中断 interrupt() 与 线程终止方法
查看>>
ubuntu下为Intellij IDEA 添加启动器
查看>>
eZ430 Chronos 的 eZ430_Chronos_CC.dll 中提供的函数收集
查看>>
Debian8下apt-get install slime失败fatal error 6死锁问题解决
查看>>
ThinkPad E450 U盘启动
查看>>
使用工具将数字进行提取的方法
查看>>
CentOs6.5 安装rabbitmq
查看>>
玩转PS路径,轻松画logo!
查看>>
git 创建 切换分支
查看>>
是否可以从一个static方法内部发出对非static方法的调用
查看>>