sgu 259
2013-04-05 17:38
501 查看
/* greedy method sort the leaflets by Li by descending order let sumTk = Ti + T2 + ..... Tk answer = max ( sumTk + Lk), k = 1...n proofproof by contradiction : 假设最优序列为 a = { 1, 2, 3 ....i, j ... n } (j = i + 1, Li < Lj ) 构造序列 b = { 1,2,3 .....j, i ....n } ans(a) = max {sumT(i-1)+Ti+Li, sumT(i-1)+Ti+Tj+Lj, sumTk+Lk }, k != i, j ans(b) = max {sumT(i-1)+Tj+Lj, sumT(i-1)+Tj+Ti+Li, sumTk+Lk }, k != i, j because Li < Lj, so Ti+Tj+Lj > Tj+Ti+Li and it is obvious that Ti+Tj+Lj > Tj+Lj we come to conclusion: ans(a) >= ans(b) , this means a is not the best ans. */ #include <stdio.h> #include <stdlib.h> #define SIZE 100 typedef struct { int T; int L; }TL; int cmp(const void* a, const void* b) { TL* pa = (TL*)a; TL* pb = (TL*)b; return (pb->L) - (pa->L); } int main() { int n, i; TL tl[SIZE]; scanf("%d", &n); for (i=0; i<n; ++i) { scanf("%d", &tl[i].T); } for (i=0; i<n; ++i) { scanf("%d", &tl[i].L); } qsort(tl, n, sizeof(TL), cmp); int s = 0; int e; int ans = 0; for (i=0; i<n; ++i) { s += tl[i].T; e = s + tl[i].L; if (e > ans) { ans = e; } } printf("%d\n", ans); return 0; }
相关文章推荐
- SGU 259 单机调度问题 +贪心 及此题解法的证明
- sgu259 Printed PR 贪心
- SGU 259 单机调度问题 +贪心 及此题解法的证明
- sgu 259 分类: sgu 2015-06-17 01:50 19人阅读 评论(0) 收藏
- sgu 259
- SGU 259 Printed PR 贪心 单机调度问题
- SGU 130 Circle(卡特兰数)
- SGU 152 Making round(水~)
- SGU 199 Beautiful People 二维最长递增子序列
- SGU 294 He's Circle(Polya原理+高精度)
- SGU 149 Computer Network(树形DP)
- SGU 114 Telecasting station
- SGU 507 Treediff(平衡树)
- SGU 101 - 120小结
- sgu 390 购票(上下界数位dp)
- 数论 + 扩展欧几里得 - SGU 106. The equation
- SGU 495 期望 简单推公式
- SGU - 115 Calendar(水题)
- SGU 271 Book Pile(deque)
- SGU 142. Keyword(暴力枚举)