zoukankan      html  css  js  c++  java
  • toj 3616 Add number (没想到啊~~)

    Add number

    时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte
    总提交: 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
    

    题目来源

    第四届北京邮电大学程序设计竞赛 2010

     

     1 #include <stdio.h>
     2 int main()
     3 {
     4     int T;
     5     scanf("%d", &T);
     6     while(T--){
     7         int n, m, k;
     8         scanf("%d %d %d", &n, &m, &k);
     9         int a[100];
    10         for(int i = 0; i < m; i++){
    11             scanf("%d", a+i);
    12         }
    13         int sum = 0;
    14         int tmp = 1;
    15         while(sum < n && k >= 0){
    16             bool flag = false;
    17             for(int i = 0; i < m; i++){
    18                 if(a[i] && a[i] <= tmp){
    19                     sum += a[i];
    20                     a[i] = 0;
    21                     flag = true;
    22                 }
    23             }
    24             if(!flag){
    25                 sum += tmp;
    26                 k--;
    27             }
    28             tmp = sum + 1;
    29         }
    30         if(k >= 0 && sum >= n){
    31             puts("YES");
    32         }
    33         else{
    34             puts("NO");
    35         }
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    oracle权限配置
    oracle锁表处理
    小组成员
    个人项目 Individual Project
    Java单元测试框架 JUnit
    MyEclipse的快捷键大全(超级实用,方便)
    vs2008 连接 vss2005 出现 analyze utility 错误的解决方法
    EXTJS gridpanel 动态设置表头
    IE8不能上网的问题
    一些事件的评论
  • 原文地址:https://www.cnblogs.com/luotinghao/p/3411224.html
Copyright © 2011-2022 走看看