24h購物| | PChome| 登入
2013-07-22 19:59:24| 人氣2,019| 回應0 | 上一篇 | 下一篇

[UVA][greedy] 11269 - Setting Problems

推薦 0 收藏 0 轉貼0 訂閱站台

Problem J
Setting Problems

Input: Standard Input

Output: Standard Output

 

As you see, setting problems fora programming contest is a tough job. There are so many things to do likecreating problems, solutions, data files, verification of problem statements,writing alternate judge solutions etc. etc. Given the responsibility ofcreating the problemset for ‘If you can not crash judges by solutions, crashcontestants by problems’ programming contest, Sultan & GolapiBaba haverealized that to the backbone. Finally they agree that they will set Nproblems for the contest. For each of the problems, first Sultan will createthe problem statement, solution & i/o data. Afterhe finishes his work, GolapiBaba does the verification & alternate solutionwriting part for that particular problem. Each of them needs a particularamount of time to complete their tasks for a certain problem. Also, none ofthem works on more than one problem at a time. Note that, GolapiBaba can startworking on a problem immediately after Sultan finishes that problem or he maywish to start that problem later.

 

You will be given the times that Sultan& GolapiBaba requires to complete their respective tasks for every singleproblem. Determine the minimum possible time required to complete the wholeproblemset.

 

Input

 

There are around 50 test cases. Eachtest case starts with a single integer N (1<=N<=20), thenumber of problems in the contest. The next line contains N integers Si(1<=Si<=1001<=i<=N) where Sidenotes the time required for Sultan to complete his tasks for problem i. The nextline has N more integers Gi (1<=Gi<=100,1<=i<=N) where Gi denotes the time required forGolapibaba to complete his tasks on problem i.

 

Output

 

For each test case, print theminimum time required to complete the problemset.

 

Sample Input

Sample Output

3

8 1 6

1 6 3

3

4 5 6

1 1 6

 

16

16

 


Problemsetter: Mohammad Mahmudur Rahman

Special Thanks To: Abdullah Al Mahmud

題目描述:

一個人先把題目生出來,然後緊接另一個人進行檢查動作。每一題分別有兩個時間消耗,對於生題目以及檢查的時間,如何排列順序,使得時間花費長度最短。兩個人是同時進行動作的,但第二個人總是要等題目創完才能進行該題的檢查。

題目解法:

根據兩個相鄰的方案進行排序,又或者可以參照 

http://www3.tcgs.tc.edu.tw/npsc/index.php?topic=118.0

greedy 就是了。

#include <stdio.h>
#include <algorithm>
using namespace std;
struct E {
    int s, q;
    bool operator<(const E &a) const {
        return s+max(a.s, q)+a.q < a.s+max(s, a.q)+q;
    }
};
int main() {
    int n, i;
    E D[105];
    while(scanf("%d", &n) == 1) {
        for(i = 0; i < n; i++)
            scanf("%d", &D[i].s);
        for(i = 0; i < n; i++)
            scanf("%d", &D[i].q);
        sort(D, D+n);
        int ret = 0, ss = 0;
        for(i = 0; i < n; i++) {
            ss += D[i].s;
            ret = max(ret, ss);
            ret = ret+D[i].q;
        }
        printf("%d\n", ret);
    }
    return 0;
}

台長: Morris
人氣(2,019) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][隨機] 10982 - Troublemakers
此分類上一篇:[UVA][dp] 10086 - Test the Rods

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文