Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdio>
  4. #include <string>
  5. #include <cassert>
  6. #include <cmath>
  7.  
  8. typedef long long i64;
  9.  
  10. using namespace std;
  11.  
  12. void relax(int& val, int newval) {
  13. if (val == -1 || val > newval) {
  14. val = newval;
  15. }
  16. }
  17.  
  18. const int MINS = 24 * 60;
  19. // vector<vector<vector<int> > > d(MINS + 1, vector<vector<int> >(MINS + 1, vector<int>(2, -1)));
  20. int d[MINS][MINS][2];
  21.  
  22.  
  23. int main() {
  24. freopen("input.txt", "r" , stdin);
  25. freopen("output.txt", "w" , stdout);
  26.  
  27. int tests;
  28. cin >> tests;
  29. // vector<vector<vector<int> > > d(MINS + 1, vector<vector<int> >(MINS + 1, vector<int>(2, -1)));
  30.  
  31. for (int test = 1; test <= tests; test++) {
  32. cout << "Case #" << test << ": ";
  33.  
  34. int n, m;
  35. cin >> n >> m;
  36.  
  37. vector<int> busy[2];
  38. busy[0].assign(MINS, 0);
  39. busy[1].assign(MINS, 0);
  40.  
  41. for (int i = 0; i < n; i++) {
  42. int l, c;
  43. cin >> l >> c;
  44. for (int j = l; j < l + c; j++) {
  45. busy[0][j] = true;
  46. }
  47. }
  48.  
  49.  
  50. for (int i = 0; i < m; i++) {
  51. int l, c;
  52. cin >> l >> c;
  53. for (int j = l; j < l + c; j++) {
  54. busy[1][j] = true;
  55. }
  56. }
  57.  
  58.  
  59. cout << "ASDASD" << endl;
  60. d[0][0][0] = 0;
  61. d[0][0][1] = 0;
  62. for (int i = 0; i < MINS; i++) {
  63. for (int j = 0; j <= i; j++) {
  64. if (d[i][j][0] != -1) {
  65. if (!busy[0][i]) {
  66. relax(d[i + 1][j + 1][0], d[i][j][0]);
  67. }
  68. if (!busy[1][i]) {
  69. relax(d[i + 1][j][1], d[i][j][0] + 1);
  70. }
  71. }
  72.  
  73. if (d[i][j][1] != -1) {
  74. if (!busy[0][i]) {
  75. relax(d[i + 1][j + 1][0], d[i][j][1] + 1);
  76. }
  77. if (!busy[1][i]) {
  78. relax(d[i + 1][j][1], d[i][j][1]);
  79. }
  80. }
  81. }
  82. }
  83.  
  84. // cout << min(d[MINS][MINS / 2][0], d[MINS][MINS / 2][1]) << endl;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement