博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva201 Squares
阅读量:5331 次
发布时间:2019-06-14

本文共 3134 字,大约阅读时间需要 10 分钟。

 

  

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.

 

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.

 

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.

 

 

416H 1 1H 1 3H 2 1H 2 2H 2 3H 3 2H 4 2H 4 3V 1 1V 2 1V 2 2V 2 3V 3 2V 4 1V 4 2V 4 323H 1 1H 2 1V 2 1

 

 

Problem #12 square (s) of size 11 square (s) of size 2**********************************Problem #2No completed squares can be found. 输出的要求比较多啊。。。
1 #include
2 #include
3 4 using namespace std; 5 int A[10][10],D[10][10]; 6 7 void Initializer(int); 8 void Input_Dates(int); 9 int Judge(int,int);10 int JudgePoint(int,int,int);11 int main()12 {13 int a,b;14 int Flag;15 int Flag1=0;16 while(cin >> a >> b)17 {18 Flag=1;19 Initializer(a);20 Input_Dates(b);21 if(Flag1)22 {23 cout << endl << "**********************************"24 << endl << endl;25 }26 cout << "Problem #" << Flag1+1 << endl << endl;27 Flag1++;28 for(int i=1;i
> c >> a >> b;53 if(c=='H')54 A[a][b]=1;55 if(c=='V')56 D[b][a]=1;57 }58 }59 int Judge(int n,int a)60 {61 int Sum=0;62 for(int i=1;i<=a-n;i++)63 for(int j=1;j<=a-n;j++)64 Sum+=JudgePoint(i,j,n);65 return Sum;66 }67 int JudgePoint(int x,int y,int n)68 {69 for(int i=0;i
View Code

 

转载于:https://www.cnblogs.com/I-love-HLD/p/4204664.html

你可能感兴趣的文章
codeforces#234_div2_C Inna and Huge Candy Matrix
查看>>
客户端判断
查看>>
C# 管道式编程
查看>>
发布一个高效的JavaScript分析、压缩工具 JavaScript Analyser
查看>>
ASP.NET Web Forms的改进
查看>>
64位下的Visual Studio的编辑并继续
查看>>
Elasticsearch中Mapping
查看>>
find_job_start
查看>>
mybatis总结之一
查看>>
linux
查看>>
人工智能需要具备哪些数学基础?
查看>>
Python Flask框架入门
查看>>
rabbitmq 高可用记录
查看>>
虚拟化
查看>>
技嘉主板BIOS恢复方法
查看>>
NetBeans的(默认)快捷键
查看>>
POJ - 2175 Evacuation Plan (最小费用流消圈)
查看>>
控制鼠标滚轮滚动的两种方法
查看>>
共享内存
查看>>
从零开始学JavaWeb
查看>>