zoukankan      html  css  js  c++  java
  • usaco-4.2-job-passed

    初看真以为是网络流呢,实际上应是贪心算法,最简洁的算法:

    /*
    ID: qq104801
    LANG: C++
    TASK: job
    */
    
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <algorithm>
    using namespace std;
    
    const int inf=1<<30;
    const int nmax=35;
    int n;
    int a[nmax],b[nmax];
    int sa[nmax],sb[nmax];
    int cost_a[nmax*nmax],cost_b[nmax*nmax];
    
    void test()
    {    
        freopen("job.in","r",stdin);
        freopen("job.out","w",stdout);  
        int temp1,temp2;
    
        cin>>n>>a[0]>>b[0];
        for(int i=1;i<=a[0];i++)
            cin>>a[i];
        for(int i=1;i<=b[0];i++)
            cin>>b[i];
    
        int i,j,k,t;
        for(t=1;t<=n;t++)
        {
            k=inf;
            for(i=1;i<=a[0];i++)
                if(sa[i]+a[i]<k) k=sa[i]+a[i],j=i;
            cost_a[t]=sa[j]=k;
    
            k=inf;
            for(i=1;i<=b[0];i++)
                if(sb[i]+b[i]<k) k=sb[i]+b[i],j=i;
            cost_b[t]=sb[j]=k;        
        }
        sort(cost_a,cost_a+n);
        sort(cost_b,cost_b+n);
        for(k=i=1;i<=n;++i)
            k=max(k,cost_a[i]+cost_b[n-i+1]);
        cout<<cost_a[n]<<" "<<k<<endl;
    }
    
    int main () 
    {        
        test();        
        return 0;
    }

    test data:

    USACO Training
    Grader Results     
    19 users online
    BRA/1 CHN/8 IND/1 TJK/1 TWN/1 USA/7
    
    USER: cn tom [qq104801]
    TASK: job
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.008 secs, 3384 KB]
       Test 2: TEST OK [0.005 secs, 3384 KB]
       Test 3: TEST OK [0.003 secs, 3384 KB]
       Test 4: TEST OK [0.003 secs, 3384 KB]
       Test 5: TEST OK [0.003 secs, 3384 KB]
       Test 6: TEST OK [0.003 secs, 3384 KB]
       Test 7: TEST OK [0.003 secs, 3384 KB]
       Test 8: TEST OK [0.003 secs, 3384 KB]
       Test 9: TEST OK [0.003 secs, 3384 KB]
       Test 10: TEST OK [0.003 secs, 3384 KB]
       Test 11: TEST OK [0.005 secs, 3384 KB]
       Test 12: TEST OK [0.003 secs, 3384 KB]
    
    All tests OK.
    
    Your program ('job') produced all correct answers! This is your submission #2 for this problem. Congratulations!
    
    Here are the test data inputs:
    
    ------- test 1 ----
    5 2 3
    1 1
    3 1 4
    ------- test 2 ----
    2 2 2
    3 5
    8 5
    ------- test 3 ----
    10 1 2
    1
    2 3
    ------- test 4 ----
    10 2 1
    3 19
    10
    ------- test 5 ----
    10 1 5
    15
    6 2 4 4 20
    ------- test 6 ----
    10 5 1
    6 20 9 8 12
    2
    ------- test 7 ----
    100 2 2
    2 3
    2 3
    ------- test 8 ----
    100 5 5
    18 15 4 2 6
    4 8 9 2 3
    ------- test 9 ----
    100 10 10
    7 20 7 3 16 8 16 10 4 1
    3 5 7 2 18 5 13 8 4 7
    ------- test 10 ----
    1000 2 3
    1 1
    2 6 7
    ------- test 11 ----
    1000 2 1
    8 5
    13
    ------- test 12 ----
    1000 30 30
    15 15 2 1 13 2 1 15 12 2 3 16 15 5 13 6 17 14 17 2 9 9 13 12 14 8 2 8 12 1
    19 2 20 6 2 10 16 9 13 6 13 18 9 1 7 14 5 2 5 14 1 13 11 2 4 17 8 20 8 19
    
    Keep up the good work!
    Thanks for your submission!
    /***********************************************

    看书看原版,原汁原味。

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

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

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

    你会知其所以然,呵呵。

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

  • 相关阅读:
    Hadoop生态圈-Hive快速入门篇之HQL的基础语法
    Hadoop生态圈-Hive快速入门篇之Hive环境搭建
    Hadoop生态圈-zookeeper的API用法详解
    Hadoop生态圈-zookeeper完全分布式部署
    Hadoop基础-MapReduce的工作原理第一弹
    Hadoop基础-HDFS的读取与写入过程
    java基础-回调函数(callback)
    Hadoop基础-网络拓扑机架感知及其实现
    Hadoop基础-HDFS数据清理过程之校验过程代码分析
    Hadoop基础-Protocol Buffers串行化与反串行化
  • 原文地址:https://www.cnblogs.com/dpblue/p/3978772.html
Copyright © 2011-2022 走看看