码迷,mamicode.com
首页 > 其他好文 > 详细

usaco-4.2-job-passed

时间:2014-09-18 13:05:03      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   div   sp   

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

/*
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!

 

usaco-4.2-job-passed

标签:style   blog   color   io   os   ar   for   div   sp   

原文地址:http://www.cnblogs.com/dpblue/p/3978772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!