首页 > 代码库 > uva 1103
uva 1103
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <cstdlib>#include <stack>#include <cctype>#include <string>#include <malloc.h>#include <queue>#include <map>using namespace std;const int INF = 0xffffff;const double Pi = 4 * atan(1);const int Maxn = 200 + 10;int dir2[8][2] = {{-1,0},{0,-1},{-1,1},{1,-1},{-1,-1},{1,0},{0,1},{1,1}};int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};int m,n;int graph[Maxn][Maxn];char alpha[] = "ADJKSW";int con[6];int dic[6][2] = {{1,0},{3,2},{5,1},{4,4},{0,5},{2,3}};int num[16][4] = {{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1}, {0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1}, {1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1}, {1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}};int cnt;void dfsZero(int r,int c){ if(r < 0 || r >= n || c < 0 || c >= m || graph[r][c] != 0) return; graph[r][c] = -1; for(int i = 0;i < 4;i++){ int xx = dir[i][0] + r; int yy = dir[i][1] + c; dfsZero(xx,yy); }}void dfs(int r,int c){ if(r < 0 || r >= n || c < 0 || c >= m || graph[r][c] == -1) return; if(graph[r][c] == 0){ cnt++; dfsZero(r,c); return; } graph[r][c] = -1; for(int i = 0;i < 4;i++){ int xx = dir[i][0] + r; int yy = dir[i][1] + c; dfs(xx,yy); }}int main(){#ifndef ONLINE_JUDGE freopen("inpt.txt","r",stdin);#endif int cas = 0; while(cin >> n >> m && n && m){ memset(graph,0,sizeof(graph)); memset(con,0,sizeof(con)); char str[Maxn]; for(int i = 0;i < n;i++){ cin >> str; int len = 0; for(int j = 0;j < m;j++){ if(str[j] == ‘0‘){ for(int k = 0;k < 4;k++) graph[i][len++] = 0; continue; } int tmp; if(isalpha(str[j])) tmp = str[j] - ‘a‘ + 10; else tmp = str[j] - ‘0‘; for(int k = 0;k < 4;k++){ graph[i][len++] = num[tmp][k]; } } } m *= 4; for(int i = 0;i < n;i++){ if(graph[i][0] == 0) dfsZero(i,0); if(graph[i][m-1] == 0) dfsZero(i,m-1); } for(int j = 0;j < m;j++){ if(graph[0][j] == 0) dfsZero(0,j); if(graph[n-1][j] == 0) dfsZero(n-1,j); } for(int i = 0;i < n;i++){ for(int j = 0;j < m;j++){ if(graph[i][j] == 1){ cnt = 0; dfs(i,j); for(int k = 0;k < 6;k++){ if(cnt == dic[k][0]){ con[ dic[k][1] ]++; break; } } } } } cout << "Case " << ++cas << ": "; for(int i = 0;i < 6;i++){ for(int j = 0;j < con[i];j++){ cout << alpha[i]; } } cout << endl; } return 0;}
测试数据:
6 2007c447c30006 250000000000000000000000000000000000000000000000000000001fe0000000000007c000000003fe0000000000007c00000000000000000000000000000000000000000000000000000010 30007785487485787000007f01e000016 2007e427e427e427e427e427e00004a0016 10123456789abcdef9 2007e427e427e427e0043 2007e007e427e427e427e007e427e007e427e427e007e427e427e427e427e007e427e427e427e427e427e00200 500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000100 2500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f800000000000000000000001fe00000000000000000000007ff00000000000000000000007ff8000000000000000000000f8f8000000000000000000001f07c000000000000000000001e03c000000000018000000001e01c00000000003c000000001c01c00000000007c000000003c01e0000000000f8000000003c01e0000000001f0000000001c01c0000000003f0000000001c01c0000000007e0000000001e01c000000000fc0000000001e03c000000001fc0000000000e03c000000001fc0000000000f038000000003ff0000000000f078000000003ff80000000007870000000007ff800000000038f0000000007cfc0000000003ce0000000007c7c0000000781fc0f0000000f87c00000007ffffff0000000f07c00000007ffffff0000000f07c00000007ffffff0000001f07c00000007ffffff0000000e03e00000007fcf81f0000000603e0000000000f8000000000003e0000000000f8000000000003e0000000000f8000000000003e0000000000f8000000000001e0000000000f8000000000001f0000000000fc000000000001f0000000000fc000000000001f0000000000fc000000000001f0000000000fc000000000000f0000000001fc000000000000f8000000001fc000000000000f8000000001fc000000000000f8000000001fc000000000000f8000000001fe000000000000f8000000001fe00000000000078000000001fe0000000000007c000000001fe0000000000007c000000003fe0000000000007c000000003fe0000000000007c000000003fe0000000000007c000000003fe0000c00000003c000000000000003ff0000003c000000000000007ff8000003e00000000000001fffc000003e00000000000003e03f000003e00000000000007c00f000003e0000000000000f0003800003f0000000000000e0001c00003fc000000000001c0001e00007fe000000000003c0000e0000fff000000000073c000070000fdf0000000001ff8000070001f0f8000000001ff8000070001e078000000003cf0000078001e038000000003870000033001e03800000000307800003fc01e03800000000703800007fe00e03800000000703800007ce00e03800000000703c000078700703800000000701e0000f0700701000000000701e0000e0700300000000000700f0001c07000000000000006007800380600000000000000e003e00700600000000000000e001fe7e00600000000000000e000fffc00e00000000000000e0000ff000e00000000000000f800038000e00000000000000fff0000000e00000000000000fffff00000e0000000000000003ffffe000c000000000000000007ffffc0c00000000000000000007ffffc000000000000000000000fffc00000000000000000000001fc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000150 3800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000f80000000001fff00000000780000000000001fe0000000007fff80000000ff0000000000007ff000000000ffffe0000001ff8000000000007ff800000003fffff0000001fffc0000000000f8f800000007fffffc000001fffe0000000001f07c0000000ffffffe000000ffff0000000001e03c0000001fffffff000000ffff8000000001e01c0000003fffffff0000007fffc000000001c01c0000003fffffff8000007fefc000000003c01e0000007fffffffc000003f83c000000003c01e000000ffffffffc000001f81e000000001c01c000000fffc0fffe000001f01e000000001c01c000001fff003ffe000000f01e000000001e01c000001ffe001fff000000f00e000000001e03c000003ffc0007ff000001e00f000000000e03c000003ff80007ff800001e00f000000000f038000007ff80003ff800001e00f000000000f078000007ff00003ff800001e00f0000000007870000007ff00001ffc00000e00e00000000038f000000fff00001ffc00000e00e0000000003ce000000ffe00000ffc00000e00e0000000781fc0f0000ffe00000ffc00000f00e00000007ffffff0000ffc00000ffc00000f01e00000007ffffff0000ffc00000ffc00000f01e00000007ffffff0000ffc00000ffc00000701c00000007ffffff0000ffc00000ffc00000781c00000007fcf81f0000ffc000007fc00000783c0000000000f8000000ffc000007fc0000038380000000000f8000000ffc000007fc000003c780000000000f8000000ffc000007fc000001c780000000000f8000000ffc000007fc000001e700000000000f8000000ffc000007fc000200ef00800000000fc000000ffc00000ffc0003f8fe3f800000000fc000000ffc00000ffc0003ffffff800000000fc000000ffc00000ffc0003ffffff800000000fc000000ffc00000ffc0003ffffff800000001fc000000ffc00000ffc0003ffffff800000001fc0000007fe00000ff80003ffffff800000001fc0000007fe00000ff80003fffdff800000001fc0000007fe00000ff80003c03c00000000001fe0000007ff00001ff80000007c00000000001fe0000003ff00001ff00000007c00000000001fe0000003ff00001ff00000007c00000000001fe0000001ff80003ff00000007c00000000003fe0000001ff80003fe00000007c00000000003fe0000001ff80003fe00000007c00000000003fe0000000ffc0007fe00000007c00000000003fe0000000ffc0007fc00000007c000000000000000000007fe0007fc00000007c000000000000000000007fe000ff800000007c000000000000000000007ff001ff800000007c000000000000000000003ff001ff800000007c000000000000000000001ff803ff000000007c002000000000000000001ff803ff000000007c006000000000000000000ffc07fe000000007c006000000000000000000ffc0ffc000000007c00c000000000000000000ffe0ffc000000003e01c0000000000000000007ff0ff8000000003f03c0000000000000000003ff1ff0000000003f8f80000000000003c00001ffbff00000f0001fff80000000000003ffc001ffffe0007ff0000fff80000000000003fffff1ffffe3fffff00007ff80000000000003fffffffffffffffff00001ff00000000000003fffffffffffffffff00000ff00000000000003fffffffffffffffff000007f00000000000003fffffffffffffffff000001e00000000000003fffffffffffffffff000000e00000000000003fffffffffffffffff000000200000000000003fffffffffffffffff000000000000000000003fffffffffffffffff000000000000000000003fffffffffffffffff000000000000000000003fffffffffffffffff000000000000000000003fffffffffffffffff000000000000000000003fffffffffffffffff000000000000000000003fffffc1ffe0007fff000000000000000000003ff80000ffe000000f0000000000000000000038000000ffe00000000000000000000000000000000001fff00000000000000000000000000000000001fff00000000000000000000000000000000001fff00000000000000000000000000000000001fff00000000000000000000000000000000001fff00000000000000000000000000000000001fff00000000000000000000000000000000003fff00000000000000000000000000000000003fff00000000000000000000000000000000003fff0000000fc000000000000000000fe000003fff8000003ff000000000000000003ffc00003fff8000007ffc0000000000000000fffe00003fff800000fcfc0000000000000001f01f00003fff800001f03e0000000000000003e00f80003fff800003e01f0000000000000003e00780003fff800003e00f0000000000000003e00780003fff800003c00f0000000000000003e00f80003fff800003c00f0000000000000001f00f00007fff800003c00f0000000000000000f81e00007fffc00003e00f00000000000000007c3c00007fffc00001e01e00000000000000003e7800007fffc00000f01e00000000000000fffffffe007fffc00000f03c00000000000000fffffffe007fffc00000787800000000000000fffffffe007fffc000003cf0000000000000000007c000007fffe000f81fe07c0000000000000007e000007fffe000fffffffc0000000000000007e000007fffe000fffffffc000000000000000fe000007fffe000fffffffc000000000000000ff00000ffffe000ffc7c0fc000000000000000ff00000ffffe0000007c000000000000000001ff00000ffffe000000fc000000000000000001ff00000ffffe000000fc000000000000000001ff80000ffffe000000fc000000000000000001ff80000ffffe000000fc000000000000000003ff80001ffffe000000fe000000000000000003ff80001ffffe000000fe0000000000000000000000001fffff000001fe0000000000000000000000001fffff000001fe0000000000000000000000001fffff000001fe0000000000000000000000001fffff000001ff0000000000000000000000001fffff000001ff0000000000000000000000001fffff000001ff0000000000000000000000001fffff000003ff0000000000000000000000001fffff000003ff0000000000000000000000001fffff000003ff0000000000000000000000001fffff800000000000000000000000000000003fffff800000000000000000000000000000003fffff800000000000000000000000000000003fffff800000000000000000000000000000003fffff800000000000000000000000000000003fffff800000000000000000000000000000003fffff800000000000000000000000000000003fffff800000000000000000000000000000003fffffc00000000000000000000000000000003fffffc00000000000000000000000000000007fffffc00000000000000000000000000000007fffffc00000000000000000000000000000007fffffc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0
Case 1: A
Case 2: WW
Case 3: AKW
Case 4: DWWW
Case 5: WWWWWWWW
Case 6: J
Case 7: ADJKSW
Case 8: WWWWWWWWWWWWWWWWWWWW
Case 9: AKW
Case 10: AAAAA
之前有一道uva572做铺垫,然后被推荐uva 1103,一开始愣是没读懂,然后就顺手搜的题解……哭…………啊啊啊!!!
主体思路是 把周边的空白扣去……
然后每个图案中间的空白区域数目都是不一样的,干后根据空白数目来判断相应的字母,
其中第一次WA是因为初始化没有把周边完全抠干净……23333333
总之,题很简单,嗯……太菜了……233333
uva 1103
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。