|
|
вернуться в форумwhat is the test #5? How was I wrong at it? Послано yang 15 окт 2011 17:48 My solution is that 1. I calulate how many passengers go off when the train arrive the station i , called Di[i] (assume we are doing on the first turn that is from Vladivostok to Moscow). And I also have similar manipulation on doing the second turn that is from Moscow to Vladivostok), called Ve[i] 2. Then, I do for (i = 2; i <= n; i++) to browse all stations that the train will come. At station i, I subtract the number of passengers who go off the train at the station (i - 1) and plus the number of passengers who will come to the station i. And, I find the MAX from them at every station i, called luotDi. I do the same with the second turn from Moscow to Vladi..., called luotVe 4. I find maxPassengers = max(luotDi, luotVe) 5. I print the result (how many cars) = maxPassengers / 36 + 1 * (maxPassengers % 36 == 0 ? 0 : 1) I can't find what I was wrong. Please help me! Here my source code #include <iostream> using namespace std; int main() { int n; int tam; int a[106][106]; int Di[106]; int Ve[106];
int luotDi = 0; int luotVe = 0; cin >> n; for (int i = 0; i <= n + 5; i++) { Di[i] = Ve[i] = 0; }
for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> a[i][j]; if (i < j) { Di[j] += a[i][j]; } else { if (i > j) Ve[j] += a[i][j]; } } }
// the first turn (Vla... -> Moscow) int soKhach = 0; // station j th for (int j = 2; j <= n; j++) { // drop passengers soKhach -= Di[j - 1];
// pick up passengers for (int i = 1; i < j; i++) { soKhach += a[i][j]; }
// find MAX if (soKhach > luotDi) { luotDi = soKhach; } }
// the second turn (Moscow -> Vla...) soKhach = 0; // station j th for (int j = n - 1; j >= 1; j--) { // drop passenger soKhach -= Ve[j + 1]; // pick up passenger for (int i = n; i > j; i--) { soKhach += a[i][j]; } // find MAX if (soKhach > luotVe) { luotVe = soKhach; } }
int result; float lDi = (float) luotDi; float lVe = (float) luotVe; if (luotDi > luotVe) { lDi = lDi / 36; result = (int) lDi; if (result < lDi) { result++; } } else { lVe = lVe / 36; result = (int) lVe; if (result < lVe) { result++; } }
cout << result; return 0; } Thanks very much! Edited by author 15.10.2011 17:52 Re: what is the test #5? How was I wrong at it? Послано b3cta3 16 окт 2011 12:27 The way you calculate drop and pick up passengers is wrong :(. Edited by author 16.10.2011 12:29 Re: what is the test #5? How was I wrong at it? Edited by author 23.11.2012 18:15 |
|
|