uva201_Squares

1

太坑了!

测试数据过,上传总是WA,像这种思路比较直白的模拟题我真心要抓狂了,最后比着思路一样但是已经AC的代码,一点一点替换代码,上传测试,最后终于发现是输出格式的问题。前前后后起码WA了我20来次......

UVa没有Presentation Error,PE格式错误啊!什么都来个WA,坑啊--

2

不过时间也没有白费,这个格式错误确实比较隐蔽,长经验值了。

题目的Output要求是这样的:

 For each record, label the corresponding output with ‘Problem #1’, ‘Problem #2’, and so forth. Outputfor 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. Separateoutput for successive input records by a line of asterisks between two blank lines, like in the samplebelow.

关键在这句:Separateoutput for successive input records by a line of asterisks between two blank lines, like in the samplebelow.

是说像示例一样,用两个空白行所夹的由星号组成的星号线,将成功的两个测试案例的输出分隔开。(忽略我的翻译质量)

其实提出了一个隐晦的条件,就是说只在成功输出的两个测试案例之间才会有这样的“两个空白行所夹的由星号组成的星号线”,那么关键点来了,对于最后一个测试案例之后,是没有星号线的,同样,也是不加一行空白行的!!我想起了HDU上的a+b题,好像是有一道是一样要求最后没有空白行,但是也没这么隐蔽!比如最后的输出可能这样,一种是{cout<<endl<<"********************************"<<endl;}另一种是{cout<<"************************************************"<<endl;其他语句cout<<正常输出结果<<endl;|,这里用前者,就可以AC。

3

code:

#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int h[20][20];
int v[20][20];
int size_[20];
int n,m;
int obj=0;

void judge(int i,int j)//这是关键部分的代码,用来判读那是否能构成square;
{
    int a1=n-i;
    int a2=n-j;
    int small=min(a1,a2);
    for(int l=0; l<small; l++)
    {
        if(h[i][j+l]&&v[i+l][j])
        {
            int q;
            for(q=0; q<=l; q++)
            {
                if(!(h[i+l+1][j+q])||!(v[i+q][j+l+1]))
                {
                    break;
                }
                if(l==q)
                {
                    obj=1;
                    size_[l+1]++;
                }
            }
        }
        else
            break;
    }
}
void shuru()
{
	 int a1,a2;
        char s;
        for(int i=1; i<=m; i++)
        {
            cin>>s>>a1>>a2;
            if(s=='H')
            {
                h[a1][a2]=1;
            }
            if(s=='V')
            {
                v[a2][a1]=1;
            }
        }
}
void zhao()
{
    for(int i=1; i<=n-1; i++)
        {
            for(int j=1; j<=n-1; j++)
            {
                    judge(i,j);
            }
        }
}
void shuchu()
{
    for(int i=1; i<=n-1; i++)
            {
                if(size_[i]!=0)
                {
                    printf("%d square (s) of size %d\n",size_[i],i);
                }
            }
}
int main()
{
    int kase=1;
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%d",&m);
       	shuru();
        zhao();
        if(kase!=1)
        printf("\n**********************************\n\n");

        if(obj)
        {
            printf("Problem #%d\n\n",kase);
            shuchu();
        }
        else
        {
            printf("Problem #%d\n\n",kase);
            printf("No completed squares can be found.\n");
        }
        obj=0;
        memset(size_,0,sizeof(size_));
        memset(h,0,sizeof(h));
        memset(v,0,sizeof(v));
     kase++;
    }
    return 0;
}

4题目要求

 children's board game consists of a square array of dots that contains lines connecting some of the pairs of adjacent dots. One part of the game requires that the players count the number of squares of certain sizes that are formed by these lines. For example, in the figure shown below, there are 3 squares-2 of size 1 and 1 of size 2. (The ``size" of a square is the number of lines segments required to form a side.)

图(见https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=137)

Your problem is to write a program that automates the process of counting all the possible 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 dots and 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 + 1

Information 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.

Sample Input

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

Sample Output

Problem #1

2 square (s) of size 1
1 square (s) of size 2

**********************************

Problem #2

No completed squares can be found.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值