UVa 11269 - Setting Problems (贪心)

来源:互联网 发布:java程序设计课后答案 编辑:程序博客网 时间:2024/06/05 03:41

题意

一个人出题,一个人验题,求最短时间。

思路

仰慕柯神。

拿出两个事件a、b。

分别计算出a前b后、a后b前的时间。

a前b后:a.st + max(a.chk, b.st) + b.chk 
a后b前:b.st + max(b.chk, a.st) + a.chk

取小的,sort一下。

代码

  1. #include <cstdio>
  2. #include <stack>
  3. #include <list>
  4. #include <set>
  5. #include <iostream>
  6. #include <string>
  7. #include <vector>
  8. #include <queue>
  9. #include <functional>
  10. #include <cstring>
  11. #include <iomanip>
  12. #include <algorithm>
  13. #include <cctype>
  14. #include <string>
  15. #include <map>
  16. #include <cmath>
  17. using namespace std;
  18. #define LL long long
  19. #define ULL unsigned long long
  20. #define SZ(x) (int)x.size()
  21. #define Lowbit(x) ((x) & (-x))
  22. #define MP(a, b) make_pair(a, b)
  23. #define MS(arr, num) memset(arr, num, sizeof(arr))
  24. #define PB push_back
  25. #define F first
  26. #define S second
  27. #define ROP freopen("input.txt", "r", stdin);
  28. #define MID(a, b) (a + ((b - a) >> 1))
  29. #define LC rt << 1, l, mid
  30. #define RC rt << 1|1, mid + 1, r
  31. #define LRT rt << 1
  32. #define RRT rt << 1|1
  33. #define BitCount(x) __builtin_popcount(x)
  34. #define BitCountll(x) __builtin_popcountll(x)
  35. #define LeftPos(x) 32 - __builtin_clz(x) - 1
  36. #define LeftPosll(x) 64 - __builtin_clzll(x) - 1
  37. const double PI = acos(-1.0);
  38. const int INF = 0x3f3f3f3f;
  39. const double eps = 1e-8;
  40. const int MAXN = 1000 + 10;
  41. const int MOD = 1000007;
  42. const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
  43. typedef pair<int, int> pii;
  44. typedef vector<int>::iterator viti;
  45. typedef vector<pii>::iterator vitii;
  46. struct POINT
  47. {
  48. int st, chk;
  49. bool operator < (const POINT &a) const
  50. {
  51. return st + max(a.st, chk) + a.chk < a.st + max(a.chk, st) + chk;
  52. }
  53. }arr[MAXN];
  54. int main()
  55. {
  56. //ROP;
  57. int n, i, j;
  58. while (~scanf("%d", &n))
  59. {
  60. for (i = 0; i < n; i++) scanf("%d", &arr[i].st);
  61. for (i = 0; i < n; i++) scanf("%d", &arr[i].chk);
  62. sort(arr, arr + n);
  63. int ans = 0, tmp = 0;
  64. for (i = 0; i < n; i++)
  65. {
  66. tmp += arr[i].st;
  67. ans = (tmp > ans ? tmp + arr[i].chk : ans + arr[i].chk);
  68. }
  69. printf("%d\n", ans);
  70. }
  71. return 0;
  72. }
0 0
原创粉丝点击