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来看。

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

    你会知其所以然,呵呵。

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

  • 相关阅读:
    USACO Milk2 区间合并
    Codeforces 490B Queue【模拟】
    HDU 3974 Assign the task 简单搜索
    HDU 5119 Happy Matt Friends(2014北京区域赛现场赛H题 裸背包DP)
    Cin、Cout 加快效率方法
    POJ 1159 回文LCS滚动数组优化
    POJ 2479 不相交最大子段和
    POJ 1458 最长公共子序列 LCS
    在阿里最深刻的,还是职场之道给我的震撼
    精细化
  • 原文地址:https://www.cnblogs.com/dpblue/p/3978772.html
Copyright © 2011-2022 走看看