toj 3616 Add number (没想到啊~~)
Add number
总提交: 60 测试通过: 21
描述
Employees of Baidu like to play a game called Making Numbers. It goes like
this: there are two players in the game, one is called little A, the other
little B. There are some cards with a number on each one of them, little A
chooses a number X from 1 to N randomly, while little B has to choose some
cards, the sum of which equals X. Now there are already M cards with numbers,
and K blank cards. At the beginning of the game, little B is allowed to write
numbers on the blank cards. Now little B wants to know, if it is possible to
write some numbers that will assure him of the victory, that is to say, if it is
possible for him to make up any number from 1 to N with the
cards.
输入
The input consists of several test cases. The first line is an integer T,
The first line of each case shows 3 numbers, N M K, the next line follows
M numbers that are already written on M cards.
1<=N<=99999999,0<=M<=19,1<=K<=19 and the numbers on M cards
are above 0, smaller than or equals N, in non-descending order.
输出
If little B can make it, output "YES", else output "NO".
样例输入
3
15 0 4 12 3 2
3 3 3
13 3 2
3 3 3
样例输出
YES
YES
NO
题目来源
#include <stdio.h>
int main()
{
int T;
scanf("%d", &T);
while(T--){
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
int a[];
for(int i = ; i < m; i++){
scanf("%d", a+i);
}
int sum = ;
int tmp = ;
while(sum < n && k >= ){
bool flag = false;
for(int i = ; i < m; i++){
if(a[i] && a[i] <= tmp){
sum += a[i];
a[i] = ;
flag = true;
}
}
if(!flag){
sum += tmp;
k--;
}
tmp = sum + ;
}
if(k >= && sum >= n){
puts("YES");
}
else{
puts("NO");
}
}
return ;
}
toj 3616 Add number (没想到啊~~)的更多相关文章
- 【原创】这道Java基础题真的有坑!我也没想到还有续集。
前情回顾 自从我上次发了<这道Java基础题真的有坑!我求求你,认真思考后再回答.>这篇文章后.我通过这样的一个行文结构: 解析了小马哥出的这道题,让大家明白了这题的坑在哪里,这题背后隐藏 ...
- 头条编程题 万万没想到之抓捕孔连顺 JavaScript
[编程题] 万万没想到之抓捕孔连顺 时间限制:1秒 空间限制:131072K 我叫王大锤,是一名特工.我刚刚接到任务:在字节跳动大街进行埋伏,抓捕恐怖分子孔连顺.和我一起行动的还有另外两名特工,我提议 ...
- 没想到,Git居然有3种“后悔药”!
没想到,Git居然有后悔药! 你知道Git版本控制系统中都有哪些"后悔药"吗? 本文通过案例讲解git reset . git revert . git checkout在版本控制 ...
- 在做关于NIO TCP编程小案例时遇到无法监听write的问题,没想到只是我的if语句的位置放错了位置,哎,看了半天没看出来
在做关于NIO TCP编程小案例时遇到无法监听write的问题,没想到只是我的if语句的位置放错了位置,哎,看了半天没看出来 贴下课堂笔记: 在Java中使用NIO进行网络TCP套接字编程主要以下几个 ...
- centos clamav杀毒软件安装配置及查杀,没想到linux下病毒比windows还多!
centos clamav杀毒软件安装配置及查杀,没想到linux下病毒比windows还多! 一.手动安装 1.下载(官网) cd /soft wget http://www.clam ...
- 杀死众筹的N种方法:没想到山寨大军也参与了
众筹作为当下创业者筹集资金,将创意变为现实的最重要手段之一,正面临着越来越多的困难,甚至衍生出杀死众筹的N种方法.甚至这些方法还分为了两类,就众筹本身看,杀死它们的主要方法是:创业者卷钱跑路. ...
- 没想到 Google 排名第一的编程语言,为什么会这么火?
没想到吧,Python 又拿第一了! 在 Google 公布的编程语言流行指数中,Python 依旧是全球范围内最受欢迎的技术语言! 01 为什么 Python 会这么火? 核心还是因为企业需要用 ...
- 字节跳动:[编程题]万万没想到之聪明的编辑 Java
时间限制:1秒 空间限制:32768K 我叫王大锤,是一家出版社的编辑.我负责校对投稿来的英文稿件,这份工作非常烦人,因为每天都要去修正无数的拼写错误.但是,优秀的人总能在平凡的工作中发现真理.我发现 ...
- 万万没想到!ModelArts与AppCube组CP了
摘要:嘘,华为云内部都不知道的秘密玩法,我悄悄告诉您! 双"魔"合璧庆双节 ↑开局一张图,故事全靠编 华为云的一站式开发平台ModelArts和应用魔方AppCube居然能玩到一起 ...
随机推荐
- java 类初识
一.定义 成员变量 成员方法 注意: 1.成员变量有默认值,是全局变量 2.成员方法,不需要使用static 3.成员变量的默认值 整型 0 浮点型 0.0 引用数据类型 null 二.使用 1.导包 ...
- redis 5种类型
redis可以不严谨的看成: redis: { name: value, name: value, } value的数据类型: 1.字典 2.列表 3.字符串 4.集合 5.有序集合 注意: redi ...
- kafka 中 zookeeper 具体是做什么的?
zookeeper 是 kafka 不可分割的一部分,可见其重要程度,所以我们有必要了解一下 zookeeper 在 kafka 中的具体工作内容. 而且,这也是面试时经常问的. zookeeper ...
- [集训]FWT基础练习题
题意 给出n个长度为20的二进制数和数字k,每次询问给出一个二进制数,问从n个数中挑k个数(不能重复)的按位或能包含询问的组合有多少个.数字均小于等于5E5,1s. 思考 强行算出2^20个答案,再O ...
- 基于 HTML5 WebGL 的虚拟现实可视化培训系统
前言 2019 年 VR, AR, XR, 5G, 工业互联网等名词频繁出现在我们的视野中,信息的分享与虚实的结合已经成为大势所趋,5G 是新一代信息通信技术升级的重要方向,工业互联网是制造业转型升级 ...
- mui html5 plus
mui: mod:框架 mhe:头文件 mbody:内容 mta:底部 msl:轮播图 mg:九宫格 ml:图文列表 mu.post : ajax dga: 绑定事件 mui.toast :来实 ...
- 求LCM(a,b)=n的(a,b)的总对数(a<=b)
\(a={p_1} ^ {a_1} *{p_1} ^ {a_1} *..........*{p_n} ^ {a_n}\) \(b={p_1} ^ {b_1} *{p_1} ^ {b_1} *..... ...
- mongodb centos7 安装
安装MongoDB的方法有很多种,可以源代码安装,在CentOS也可以用yum源安装的方法.由于MongoDB更新得比较快,我比较喜欢用yum源安装的方法.64位Centos下的安装步骤如下: 1.准 ...
- ATL窗口
标准的Windows应用程序框架: /*------------------------------------------------------------ HELLOWIN.C -- Displ ...
- Codeforces_844
A.统计字母个数. #include<bits/stdc++.h> using namespace std; string s; int n; map<char,int> mp ...