timus 1287. Mars Canals URAL 解题报告
2013-08-07 16:16
435 查看
timus 1287. Mars Canals URAL 解题报告
一个n*n的地图上,种有两种作物,大小s,统计这牙膏啵一个segment,横竖,或者斜45°;很简单的dp,但是需要注意的是,一个点如果有两种方式来源,横着算上他是4,竖着算上他是5,那么如果保留5的话,往下转移的时候只能是竖着了; 所以dp[i][j]保留到这点最大值还不行,还得保留那个方向,一边继续往下转移……
#include<iostream> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<map> #include<algorithm> #include<string> #include<queue> #include<stack> using namespace std; #define inf 0x3f3f3f3f int f[1401][1401][8]; char base[1401][1401]; int max0(int x,int y,int cmd) {int ret=0; if(cmd==1) { for(int i=0;i<4;++i) { ret=max(ret,f[x][y][i]); } } else for(int i=4;i<8;++i) { ret=max(ret,f[x][y][i]); } return ret; } int main() { //freopen("data.in", "r", stdin); int n; cin >> n; for (int i = 0; i < n; i++) cin >> base[i]; memset(f, 0, sizeof(f)); int cnt1=0,cnt2=0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (base[i][j] == 's') { if (i > 0 && base[i - 1][j] == 's') f[i][j][0] = f[i - 1][j][0] + 1; else f[i][j][0] = 1; if (j >= 1 && base[i][j - 1] == 's') f[i][j][1] = f[i][j - 1][1] + 1; else f[i][j][1] = 1; if (i > 0 && j > 0 && base[i - 1][j - 1] == 's') f[i][j][2] = f[i - 1][j - 1][2] + 1; else f[i][j][2] = 1; if (i > 0 && j < n - 1 && base[i - 1][j + 1] == 's')f[i][j][3] = f[i - 1][j + 1][3] + 1; else f[i][j][3] = 1; cnt1=max(max0(i,j,1),cnt1); } else if (base[i][j] == 'S') { if (i > 0 && base[i - 1][j] == 'S') { f[i][j][4] = f[i - 1][j][4] + 1; } else f[i][j][4] = 1; if (j >= 1 && base[i][j - 1] == 'S') { f[i][j][5] = f[i][j - 1][5] + 1; } else f[i][j][5] = 1; if (i > 0 && j > 0 && base[i - 1][j - 1] == 'S') { f[i][j][6] = f[i - 1][j - 1][6] + 1; } else f[i][j][6] = 1; if (i > 0 && j < n - 1 && base[i - 1][j + 1] == 'S') { f[i][j][7] = f[i - 1][j + 1][7] + 1; } else f[i][j][7] = 1; cnt2=max(max0(i,j,2),cnt2); } } if (cnt1 > cnt2) { cout << "s" << endl; cout << cnt1 << endl; } else if (cnt1 < cnt2) { cout << "S" << endl; cout << cnt2 << endl; } else if (cnt1 == cnt2) { cout << "?" << endl; cout << cnt1 << endl; } }
timus 1287. Mars Canals URAL 解题报告
相关文章推荐
- timus 1185. Wall URAL 解题报告 凸包
- timus 1346. Intervals of Monotonicity URAL 解题报告 DP 小水题,阅读理解
- timus 1588. Jamaica URAL 解题报告 平面点距离和
- timus 1039. Anniversary Party URAL解题报告 树形DP
- URAL 1389 Roadworks 解题报告
- 解题报告 URAL 1051
- ural 1692 Flags for Provinces 解题报告
- URAL 1386 Maze 解题报告
- Timus 1005 解题报告
- Ural 1073 Square Country 解题报告
- Ural 1001 Reverse Root 解题报告
- URAL 1385 Interesting Number 解题报告
- Ural 1005 Stone Pilet 解题报告
- [解题报告]ural 1176 Hyperchannels
- Ural 1114. Boxes 解题报告(组合数计算)
- URAL 1699 Turning Turtles 解题报告
- URAL 1010 Discrete Function(解题报告)
- URAL 1287. Mars Canals 滚动数组+DP
- URAL 1010 Discrete Function(解题报告)
- Ural 1020 Rope 解题报告