思路:
一直向下走,当前行的下一行都是1时,那么我们肯定就不能通过该行,也就是“永远也不能到达”;当前行的下一行有一格是0的话,如果当前格的下一格是0,那我们就可以直接向下走,否则判断这个格子的左(右)是否是1,如果是,则“永远也不能到达”,否则,我们就可以走到这一格上,然后再向下走。
算法:贪心
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
int minfoot=0;
const int size=10005;
int a[size][3];
int main()
{
// freopen("porch.in","r",stdin);
// freopen("porch.out","w",stdout);
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= 2; j++) cin >> a[i][j];
if (a[1][1] == 1) {
cout << "Poor";
return 0;
}
int k = 1;
for (int i = 1; i < n; i++) {
if (a[i + 1][1] == 1 && a[i + 1][2] == 1) {
cout << "Poor";
return 0;
}
if (a[i + 1][k] == 0)
minfoot++;
else {
if (k == 2)
k = 1;
if (k == 1)
k = 2;
if (a[i][k] == 1) {
cout << "Poor";
return 0;
} else
minfoot += 2;
}
}
cout << minfoot;
return 0;
}