• usaco-4.1-nuggets-passed


    呵呵,这个数论题

    /*
    ID: qq104801
    LANG: C++
    TASK: nuggets
    */
    
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <algorithm>
    using namespace std;
    
    #define nmax 79500
    
    int d[500000],temp,n;
    
    void test()
    {    
        freopen("nuggets.in","r",stdin);
        freopen("nuggets.out","w",stdout);  
        d[0]=1;
        cin>>n;
        while(n--)
        {
            cin>>temp;
            for(int i=temp;i<=nmax;i++)if(d[i-temp])d[i]=1;
        }
        temp=0;
        for(int i=nmax;i>=0;i--)if(!d[i]){temp=i;break;}
            for(int i=nmax;i>=79000;i--)if(!d[i]){temp=0;break;}
        cout<<temp<<endl;
        
    }
    
    int main () 
    {        
        test();        
        return 0;
    }

    test data :

    USACO Training
    Grader Results     
    13 users online
    AUT/1 BGD/1 CHL/1 CHN/7 GBR/1 IND/1 SWE/1
    
    USER: cn tom [qq104801]
    TASK: nuggets
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.005 secs, 5324 KB]
       Test 2: TEST OK [0.005 secs, 5324 KB]
       Test 3: TEST OK [0.008 secs, 5324 KB]
       Test 4: TEST OK [0.008 secs, 5324 KB]
       Test 5: TEST OK [0.005 secs, 5324 KB]
       Test 6: TEST OK [0.008 secs, 5324 KB]
       Test 7: TEST OK [0.014 secs, 5324 KB]
    
    All tests OK.
    
    YOUR PROGRAM ('nuggets') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.
    
    Here are the test data inputs:
    
    ------- test 1 ----
    3
    3
    6
    10
    ------- test 2 ----
    2
    2
    3
    ------- test 3 ----
    1
    1
    ------- test 4 ----
    4
    252
    250
    254
    256
    ------- test 5 ----
    2
    255
    254
    ------- test 6 ----
    5
    251
    252
    250
    254
    256
    ------- test 7 ----
    10
    238
    240
    242
    244
    246
    248
    250
    252
    254
    255
    
    Keep up the good work!
    Thanks for your submission!
    View Code
    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

    ***********************************************/

  • 相关阅读:
    gbk学习笔记
    在freebsd下编译nodejs,出现无法找到execinfo.h头文件的错误
    php 截取GBK文档某个位置开始的n个字符
    linux下,phpstorm配置oracle jdk
    gb2312学习笔记
    freebsd下vim默认的vi操作方式太难用,可通过启用vim自带配置文件解决
    freebsd通过ssh远程登陆慢,用户认证时间长解决办法
    php输出全部gb2312编码内的汉字
    visibility:hidden 与 display:none 的区别
    java 实现文件/文件夹复制、删除、移动(二)
  • 原文地址:https://www.cnblogs.com/dpblue/p/3976085.html
Copyright © 2020-2023  润新知