记录编号 390292 评测结果 AAAAAAAAAA
题目名称 [HAOI 2010]工厂选址 最终得分 100
用户昵称 GravatarkZime 是否通过 通过
代码语言 C++ 运行时间 0.351 s
提交时间 2017-04-02 16:46:33 内存使用 1.27 MiB
显示代码纯文本
  1. ;/*kZime*/
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <vector>
  7. #include <queue>
  8. #include <stack>
  9. #include <cstdlib>
  10. #include <algorithm>
  11. #define MAXN 50005
  12. using namespace std;
  13. /*-----------------------------------------------------------------------------*/
  14. inline void File_Read() {
  15. #ifndef MYLAB
  16. freopen("factory1.in", "r", stdin);
  17. freopen("factory1.out", "w", stdout);
  18. #else
  19. // freopen("in.txt", "r", stdin);
  20. #endif
  21. }
  22.  
  23. inline int get_num() {
  24. int k = 0, f = 1; char c = getchar();
  25. for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
  26. for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
  27. return k * f;
  28. }
  29.  
  30. struct fire_energy {
  31. int c, tar;
  32. }f[MAXN];
  33.  
  34. bool cmp(fire_energy a, fire_energy b) {
  35. return a.c < b.c;
  36. }
  37.  
  38. int n, b, h, m;
  39. int cost[MAXN], hi[MAXN], a[MAXN];
  40. int sum, tot, pos;
  41.  
  42. int main() {
  43. File_Read();
  44. m = get_num();
  45. b = get_num();
  46. h = get_num();
  47. n = get_num();
  48. for(int i = 1; i <= m; i++) {
  49. a[i] = get_num();
  50. sum += a[i]; // sum代表的是总产煤
  51. }
  52. for(int i = 1; i <= n; i++) {
  53. hi[i] = get_num();
  54. }
  55. for(int i = 1; i <= m; i++) {
  56. cost[i] = get_num();
  57. tot += cost[i] * a[i]; // tot是指原厂运煤的总成本
  58. }
  59. long long ans = 0x7fffffff, now , le;
  60. for(int i = 1; i <= n; i++) {
  61. for(int j = 1; j <= m; j++) {
  62. f[j].c = get_num() - cost[j];
  63. f[j].tar = j;
  64. }
  65. sort(f + 1, f + 1 + m, cmp);
  66. now = tot, le = sum - b;//now为当前最小成本
  67. //le是剩余可判断的煤量
  68. for(int j = 1; j <= m; j++) {
  69. if(le > a[f[j].tar]) {
  70. le -= a[f[j].tar];
  71. now += f[j].c * a[f[j].tar];
  72. } else {
  73. now += le * f[j].c;
  74. break;
  75. }
  76. }
  77. if(now + hi[i] < ans) {
  78. ans = now + hi[i];
  79. pos = i;
  80. }
  81. }
  82.  
  83. printf("%d\n%lld\n", pos, ans + h);
  84.  
  85. return 0;
  86. }
  87.