Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- int main() {
- int a, b;
- cin >> a >> b;
- bool route[1005][1005];
- double path[1005][1005];
- for (int i = 0; i <= 100; i++) {
- for (int j = 0; j <= 100; j++) {
- path[i][j] = 0.0000;
- }
- }
- int q;
- cin >> q;
- for (int i = 0; i < q; i++) {
- int x, y;
- cin >> x >> y;
- route[x][y] = true;
- }
- for (int i = 0; i < a+1; i++) {
- for (int j = 0; j < a+1; j++) {
- if (i == 0 && j == 0) {
- continue;
- }
- else if (j == 0) {
- path[i][j] = path[i-1][j] + 100.00000;
- }
- else if (i == 0) {
- path[i][j] = path[i][j-1] + 100.00000;
- }
- else {
- if (route[i][j]) {
- path[i][j] = min((double)path[i-1][j]+100.00000, min((double)path[i][j-1]+100.00000, (double)path[i-1][j-1] + 141.42135623730950488016887242097));
- }
- else {
- path[i][j] = min(path[i-1][j]+100.00000, path[i][j-1]+100.00000);
- }
- }
- }
- }
- cout << round(path[a][b]) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment