sgu259 Printed PR    贪心

August 6, 2013
Sgu

link:http://acm.sgu.ru/problem.php?contest=0&problem=259 思路就是贪心. 首先要读懂题目,输入的方式,把样例读懂. 第一,打印的总时间一定.需要做的就是送出的时间尽可能的重合,这样总时间就会更少.所以,送出时间长的要尽可能的先打印,按照送出时间从大到小排序就可以了.


/*
 * =====================================================================================
 *       Filename:  259.cpp
 *        Created:  06/08/2013 10:15:09
 *         Author:  liuxueyang (lxy), 1459917536@qq.com
 *   Organization:  Hunan University
 *
 * =====================================================================================
 */

/*
ID: zypz4571
LANG: C++
TASK: 259.cpp
*/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <list>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define LL long long
const double eps=1e-9;
using namespace std;
struct Node{
    int t, l;
    bool operator < (const Node other) const {
        if (l!=other.l) return l>other.l;
        else return t<other.t;
    }
}a[111];
int main ( int argc, char *argv[] )
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin>>n) {
        for (int i = 0; i < n; ++i) cin>>a[i].t;
        for (int i = 0; i < n; ++i) cin>>a[i].l;
        int ans=0, sum=0;
        sort(a,a+n);
        for (int i = 0; i < n; ++i)  {
            sum += a[i].t;
            ans = max(ans, sum+a[i].l);
        }
        cout<<ans<<endl;
    }
        return EXIT_SUCCESS;
}                /* ----------  end of function main  ---------- */

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

comments powered by Disqus