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

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 n 2 dots (where 2 ≤ n ≤ 9) and some interconnecting horizontal and vertical lines. A record for a single board with n 2 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.

HINT

暴力破解的,使用连两个数组分别储存竖边和横边,然后判断每一个可能的正方形。使用了4个for循环来来判断,最外层循环是正方形的大小,最大到n-1。紧接着两个循环对每一个可能的顶点来判断。最里面的才是判断标准,

#include<stdio.h>
#include<stdlib.h>
#include<string.h> int result(int arrh[][10], int arrv[][10], int n); int main()
{
int n, m ,p, q;
int problem = 1;
while (scanf("%d %d", &n, &m) != EOF)
{
getchar();
int arrh[10][10] = { 0 };
int arrv[10][10] = { 0 };
char ch;
for (int i = 0;i < m;i++)
{
scanf("%c %d %d", &ch, &p, &q);getchar();
if (ch == 'H')arrh[p][q]=1;
else arrv[q][p] = 1;
}
if (problem != 1)printf("\n**********************************\n\n");
printf("Problem #%d\n\n", problem++);
if (result(arrh, arrv, n)==0)printf("No completed squares can be found.\n");
}
} int result(int arrh[][10], int arrv[][10], int n)
{
int flag = 0;
for (int i = 1;i < n;i++)
{
int sum = 0;
for (int j = 1;j <= n - i;j++)
{
for (int k = 1;k <= n - i;k++)
{
int flag1 = 0;
for (int s = 0;s<i;s++)
{
if (!arrh[j][k + s] || !arrh[j + i][k + s] || !arrv[j + s][k] || !arrv[j + s][k + i])
{
flag1 = 1;break;
}
}
if (!flag1) { sum++;flag = 1; }
}
}
if (sum)printf("%d square (s) of size %d\n", sum, i);
}
return flag;
}

Squares UVA - 201的更多相关文章

  1. 【每日一题】Squares UVA - 201 暴力+输出坑 + 读文件模板

    题意 给你n*n的图,让你数正方形 题解:暴力for每个点,对于每个点从它出发顺时针走一个正方形.走完就ans[i]++; 坑:多输了一行******,然后在那里手摸样例,无限debug orz #d ...

  2. UVa 201 Squares

    题意: 给出这样一个图,求一共有多少个大小不同或位置不同的正方形. 分析: 这种题一看就有思路,最开始的想法就是枚举正方形的位置,需要二重循环,枚举边长一重循环,判断是否为正方形又需要一重循环,复杂度 ...

  3. 【UVA】201 Squares(模拟)

    题目 题目     分析 记录一下再预处理一下.     代码 #include <bits/stdc++.h> int main() { int t=0,s,n; while(scanf ...

  4. UVa 1453 - Squares 旋转卡壳求凸包直径

    旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...

  5. UVa 1643 Angle and Squares

    题意: 如图,有n个正方形和一个角(均在第一象限中),使这些正方形与这个角构成封闭的阴影区域,求阴影区域面积的最大值. 分析: 直观上来看,当这n个正方形的对角线在一条直线上时,封闭区域的面积最大.( ...

  6. uva 1453 - Squares

    旋转卡壳算法: 直接在这个上面粘的模板 主要用途:用于求凸包的直径.宽度,两个不相交凸包间的最大距离和最小距离··· 这题就是求凸包的直径 #include <cstdio> #inclu ...

  7. UVA 4728 Squares(凸包+旋转卡壳)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...

  8. UVA 12113 Overlapping Squares

    题意: 总共有6个2*2的正方形,判断是否能够成所给的形状. 思路: 一个正方形总共有9种摆放方式,对于整个地图来说摆放方式总共有2的9次方种摆放方式.然后将地图用9*5的数组表示,正方形的位置用其8 ...

  9. UVa 1643 Angle and Squares (计算几何)

    题意:有n个正方形和一个角(均在第一象限中),使这些正方形与这个角构成封闭的阴影区域,求阴影区域面积的最大值. 析:很容易知道只有所有的正方形的对角形在一条直线时,是最大的,然后根据数学关系,就容易得 ...

随机推荐

  1. 数据处理_HIVE增量ETL的一种方式

    适用场景: 贴源层主表历史数据过大,ETL不涉及历史数据对比或聚合 处理流程: 1.确定一个业务主键字段或物理主键字段 2.确定一个可以判断增量数据范围的字段,这取决于具体的业务场景,一般选用记录的创 ...

  2. 小心你的个人信息——GitHub 热点速览 v.21.09

    作者:HelloGitHub-小鱼干 浏览过必有痕迹,有什么可以抹去社交痕迹的方法呢?social-analyzer 是一个可在 350+ 网站分析特定用户资料的工具,你可以用它来"人肉&q ...

  3. Spring Boot 老启动失败,这次再也不怕了!

    Spring Boot 项目是不是经常失败,显示一大堆的错误信息,如端口重复绑定时会打印以下异常: *************************** APPLICATION FAILED TO ...

  4. 如何读写拥有命名空间xmlns 属性的Xml文件(C#实现)

    我们在进行C#项目Xml读写开发时经常遇到一些读写问题,今天我要介绍的是遇到多个命名空间xmlns属性时如何读写此类文件. 比如下面这个Xml文件: <?xml version="1. ...

  5. new String("abc"),到底在不在常量池中存储"abc"?

    String str = new String("Hello World"); 问之:这行代码到底有没有在字符串常量池中创建"Hello World"字符串呢? ...

  6. Percona XtraDB Cluster之流量控制

    什么是流量控制? Percona XtraDB Cluster具有一种称为流控制的自调节机制.该机制有助于避免集群中最弱/最慢的成员明显落后于集群中其他成员的情况. 当集群成员在写数据很慢(同时又继续 ...

  7. Python数据格式:%s字符串,%d整型,%f浮点型

    格式化符% name="Tom" age=int(input("age")) pt2="%s你的年龄是%d"%(name,age) prin ...

  8. 微软跨平台UI框架MAUI真的要来啦

    .NET 6 preview已经上线,是时候为在BUILD 2020上宣布的新.NET Multi-platform App UI(MAUI)做准备了.对于客户端应用程序开发人员来说,这一年.NET有 ...

  9. win8 下删除服务

    1.右键 我的电脑-管理-服务和应用程序-服务,找到想要删除的服务,双击后复制服务名称. 2.管理员身份运行cmd 在命令框中输入 sc delete "secbizsrv" 就删 ...

  10. API管理工具

    开源的api文档管理系统 api文档 php 在项目中,需要协同开发,所以会写许多API文档给其他同事,以前都是写一个简单的TXT文本或Word文档,口口相传,这种方式比较老土了,所以,需要有个api ...