UVA - 201 Squares

这题吧 我觉得我方法很奇葩 看了很多人的代码 没看到跟我一样 用两个结构体的。。。

Description

Download as PDF


 Squares 

A 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.)

tex2html_wrap_inline240

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.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct N
{
    int n;
    int size;
}num[15];
struct point
{
    int up;
    int down;
    int left;
    int right;
}a[15][15];
void LIAN(point a[][15])
{
    char s;
    int x,y;
    scanf("%c",&s);
    scanf("%d%d",&x,&y);
    if(s=='H')
        a[x][y].right=1,a[x][y+1].left=1;
    else if(s=='V')
        a[y][x].down=1,a[y+1][x].up=1;
    getchar();
}
int CHECK(point a[][15],int i,N num[],int n)
{
    int j,k,ss=0,l,sign;
    for(j=1;j<=n-i;j++)
        for(k=1;k<=n-i;k++)
        {sign=1;
            if(a[j][k].right==1&&a[j][k].down==1&&a[j][k+i].left==1&&a[j][k+i].down==1&&a[j+i][k].up==1&&a[j+i][k].right==1&&a[j+i][k+i].left==1&&a[j+i][k+i].up==1)
            {
                for(l=1;l<i;l++)
                {
                    if(a[j+l][k].up!=1||a[j+l][k].down!=1)
                        sign=0;
                    if(a[j][k+l].left!=1||a[j][k+l].right!=1)
                        sign=0;
                    if(a[j+l][k+i].up!=1||a[j+l][k+i].down!=1)
                        sign=0;
                    if(a[j+i][k+l].left!=1||a[j+i][k+l].right!=1)
                        sign=0;
                }
                if(sign)
                ss++;
            }
        }
        num[i].size=i;
        num[i].n=ss;
}
int main()
{
    int n,i,lian,o=0,flag;
    while(~scanf("%d",&n))
    {
        memset(num,0,sizeof(num));
        memset(a,0,sizeof(a));
        if(o)
            printf("\n**********************************\n\n");
        o++;
        scanf("%d",&lian);
        getchar();
        while(lian--)
            LIAN(a);
        printf("Problem #%d\n\n",o);
        for(i=1;i<=n;i++)
            CHECK(a,i,num,n);
        flag=0;
        for(i=1;i<15;i++)
        {
            if(num[i].n)
                printf("%d square (s) of size %d\n",num[i].n,num[i].size),flag=1;
        }
        if(!flag)
            printf("No completed squares can be found.\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]: Curves and Surfaces A Bidirectional Generating Algorithm for Rational Parametric Curves(Z. Li, L. Ma)Fast Detection of the Geometric Form of Two-Dimensional Cubic Bézier Curves(S. Vincent)Exact Evaluation of Subdivision Surfaces(eigenstructures for Catmull-Clark and Loop schemes) (J. Stam)Exact Evaluation of Catmull-Clark Subdivision Surfaces near B-Spline Boundaries(D. Lacewell, B. Burley)Smooth Two-Dimensional Interpolations: A Recipe for All Polygons(E. Malsch, J. Lin, G. Dasgupta) Normal Patches / PN-Triangles(R. Stimpson)Marching Cubes(.vol files) (R. Stimpson)Coons Patches(R. Stimpson)Exact Catmull-Clark Subdivision evaluation(and mean-curvature minimization) (F. Hecht)Laplacian Surface Editing(2D curve deformation) (O. Sorkine, D. Cohen-Or, Y. Lipman, M. Alexa, C. Roessl, H.-P. Seidel)Elasticurves: Exploiting Stroke Dynamics and Inertia for the Real-time Neatening of Sketched 2D Curves(Y. Thiel, K. Singh, R. Balakrishnan) 。 引用\[2\]: Segmentation efpisoft: hierarchical mesh segmentation based on fitting primitives(M. Attene)mesh segmentation benchmark database and viewer(X. Chen, A. Golovinskiy, T. Funkhouser)Graphite(variational shape approximation,image vectorization) \[documentation wiki\] (Authors)SegMatch: Shape Segmentation and Shape Matching from Point Cloud(T. Dey, S. Goswami)ShapeAnnotatorsegmentation tool (fitting primitives, barycentric/height/integral geodesic Morse, Plumber, Lloyd clustering)(Authors)Shape Diameter Function (SDF) segmentation tool(L. Shapira) 。 引用\[3\]:DP。对于每个'#'来说,要使图美丽就要保证每个'#'的正下方到正右下都填满'#' ....#. ....#. ...... ....## .#.... -> .#..## (题解里CV过来的) ...... .##.## ...... .##### 。 问题: Defect-free Squares是什么意思? 回答: Defect-free Squares是指在一个图形中,每个'#'的正下方到正右下方都填满了'#',从而使整个图形看起来没有缺陷。这个概念可以通过动态规划(DP)来实现,对于每个'#',需要保证其正下方到正右下方都填满了'#',从而形成一个完整的正方形。\[3\] #### 引用[.reference_title] - *1* *2* [图形学领域的关键算法及源码链接](https://blog.csdn.net/u013476464/article/details/40857873)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [ABC311 A-F](https://blog.csdn.net/Muelsyse_/article/details/131873631)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值