UVA201 Squares
2014-10-29 15:16
435 查看
Squares |
Input
The input file represents a series of game boards. Each board consists of a description of a square array of n2 dots (where 2 <= n <= 9) and some interconnecting horizontal and vertical lines. A record for a single board with n2 dotsand m interconnecting lines is formatted as follows:Line 1: n the number of dots in a single row or column of the array Line 2: m the number of interconnecting lines Each of the next m lines are of one of two types: H i j indicates a horizontal line in row i which connects the dot in column j to the one to its right in column j + 1 or V i j indicates a vertical line in column i which connects the dot in row j to the one below in row j + 1Information for each line begins in column 1. The end of input is indicated by end-of-file. The first record of the sample input below represents the board of the square above.
Output
For each record, label the corresponding output with ``Problem #1", ``Problem #2", and so forth. Output for a record consists of the number of squares of each size on the board, from the smallest to the largest. lf no squares of any size exist,your program should print an appropriate message indicating so. Separate output for successive input records by a line of asterisks between two blank lines, like in the sample below.SampleInput
4 16 H 1 1 H 1 3 H 2 1 H 2 2 H 2 3 H 3 2 H 4 2 H 4 3 V 1 1 V 2 1 V 2 2 V 2 3 V 3 2 V 4 1 V 4 2 V 4 3 2 3 H 1 1 H 2 1 V 2 1
SampleOutput
Problem #1 2 square (s) of size 1 1 square (s) of size 2 ********************************** Problem #2 No completed squares can be found.
本题做的不太好,用了四层循环。。。
#include <stdio.h>#include <string.h>int main(){#ifdef ONLINE_JUDGE#elsefreopen("in.txt","r",stdin);freopen("out.txt","w",stdout);#endifint time=1,n;while(scanf("%d",&n)!=EOF){int m;int across[16][16];int down[16][16];int cnt;memset(across,0,sizeof(across));memset(down,0,sizeof(down));scanf("%d",&m);getchar();for(int i=1; i<=m; i++){char opera;int x,y;scanf("%c",&opera);scanf("%d%d",&x,&y);getchar();if(opera=='H')across[x][y]=1;else if(opera=='V')down[y][x] = 1;}if(time!=1)printf("\n**********************************\n\n");printf("Problem #%d\n\n",time);int flag=0;for(int k=1; k<n; k++){cnt=0;int cnt1;for(int i=1; i<=n-k; i++){for(int j=1; j<=n-k; j++){cnt1=0;for(int p=j; p<j+k; p++){if(across[i][p]==1)cnt1++;if(across[i+k][p]==1)cnt1++;}for(int p=i; p<i+k; p++){if(down[p][j]==1)cnt1++;if(down[p][j+k]==1)cnt1++;}if(cnt1==4*k)cnt++;}}if(cnt!=0)printf("%d square (s) of size %d\n",cnt,k),flag=1;}if(flag==0)printf("No completed squares can be found.\n");time++;}return 0;}[/code]
Squares |
Input
The input file represents a series of game boards. Each board consists of a description of a square array of n2 dots (where 2 <= n <= 9) and some interconnecting horizontal and vertical lines. A record for a single board with n2 dotsand m interconnecting lines is formatted as follows:Line 1: n the number of dots in a single row or column of the array Line 2: m the number of interconnecting lines Each of the next m lines are of one of two types: H i j indicates a horizontal line in row i which connects the dot in column j to the one to its right in column j + 1 or V i j indicates a vertical line in column i which connects the dot in row j to the one below in row j + 1Information for each line begins in column 1. The end of input is indicated by end-of-file. The first record of the sample input below represents the board of the square above.
Output
For each record, label the corresponding output with ``Problem #1", ``Problem #2", and so forth. Output for a record consists of the number of squares of each size on the board, from the smallest to the largest. lf no squares of any size exist,your program should print an appropriate message indicating so. Separate output for successive input records by a line of asterisks between two blank lines, like in the sample below.SampleInput
4 16 H 1 1 H 1 3 H 2 1 H 2 2 H 2 3 H 3 2 H 4 2 H 4 3 V 1 1 V 2 1 V 2 2 V 2 3 V 3 2 V 4 1 V 4 2 V 4 3 2 3 H 1 1 H 2 1 V 2 1
SampleOutput
Problem #1 2 square (s) of size 1 1 square (s) of size 2 ********************************** Problem #2 No completed squares can be found.
相关文章推荐
- UVA 201 Squares
- UVa201 Squares(算法竞赛入门经典第二版习题4-2)
- UVA-201 Squares
- uva 201 Squares 暴力
- Uva201 Squares
- Squares UVa201
- uva201(poj2445) Squares(模拟)
- UVa 201 Squares(正方形)
- ACM UVa 算法题 #201 - Squares解法
- uva 201 - Squares(数正方形)
- UVA - 201 Squares(水)
- UVa 201 - Squares
- UVA - 201-Squares
- UVA - 201 Squares
- uva201正方形squares
- UVA 201 Squares——思路题
- Uva 201 Squares (暴力 + 枚举)
- UVA - 201 Squares
- UVa 201 Squares(正方形)
- UVa 201 Squares