sgu259 Printed PR    贪心

link:http://acm.sgu.ru/problem.php?contest=0&problem=259

思路就是贪心.

首先要读懂题目,输入的方式,把样例读懂.

第一,打印的总时间一定.需要做的就是送出的时间尽可能的重合,这样总时间就会更少.所以,送出时间长的要尽可能的先打印,按照送出时间从大到小排序就可以了.

 1 /*
 2  * =====================================================================================
 3  *       Filename:  259.cpp
 4  *        Created:  06/08/2013 10:15:09
 5  *         Author:  liuxueyang (lxy), 1459917536@qq.com
 6  *   Organization:  Hunan University
 7  *
 8  * =====================================================================================
 9  */
10 
11 /*
12 ID: zypz4571
13 LANG: C++
14 TASK: 259.cpp
15 */
16 #include <iostream>
17 #include <cstdlib>
18 #include <cstdio>
19 #include <cstring>
20 #include <cmath>
21 #include <cctype>
22 #include <algorithm>
23 #include <queue>
24 #include <set>
25 #include <stack>
26 #include <map>
27 #include <list>
28 #define INF 0x3f3f3f3f
29 #define MOD 1000000007
30 #define LL long long
31 const double eps=1e-9;
32 using namespace std;
33 struct Node{
34     int t, l;
35     bool operator < (const Node other) const {
36         if (l!=other.l) return l>other.l;
37         else return t<other.t;
38     }
39 }a[111];
40 int main ( int argc, char *argv[] )
41 {
42 #ifndef ONLINE_JUDGE
43     freopen("in.txt", "r", stdin);
44 #endif
45     ios::sync_with_stdio(false);
46     int n;
47     while (cin>>n) {
48         for (int i = 0; i < n; ++i) cin>>a[i].t;
49         for (int i = 0; i < n; ++i) cin>>a[i].l;
50         int ans=0, sum=0;
51         sort(a,a+n);
52         for (int i = 0; i < n; ++i)  {
53             sum += a[i].t;
54             ans = max(ans, sum+a[i].l);
55         }
56         cout<<ans<<endl;
57     }
58         return EXIT_SUCCESS;
59 }                /* ----------  end of function main  ---------- */

开始要读懂题目意思啊,读题认真.

posted on 2013-08-06 10:27  aries__liu  阅读(257)  评论(0编辑  收藏  举报