【习题 4-2 Uva201】Squares
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
注意那个星号的数量。。。
然后V x y的话,是从(y,x)向(y+1,x)连线。
H x y才是从(x,y)向(x,y+1)连线
枚举以(x,y)作为左上角的举行就ok了
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n,m;
bool a[N+10][N+10][2];
int cnt[N+5];
bool check(int x,int y,int p){
for (int i = 1;i <= p;i++)
if (a[x][y][0]){
y++;
if (y>n) break;
}else return 0;
for (int i = 1;i <= p;i++)
if (a[x][y][1]){
x++;
if (x>n) break;
}else return 0;
for (int i = 1;i <= p;i++)
if (y-1>=1 && a[x][y-1][0]){
y--;
if (y<1) break;
}else return 0;
for (int i = 1;i <= p;i++)
if (x-1>=1 && a[x-1][y][1]){
x--;
if (x<1) break;
}else return 0;
return 1;
}
int main(){
//freopen("/home/ccy/rush.txt","r",stdin);
//freopen("/home/ccy/rush_out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0);
int kase = 0;
while (cin >> n){
if (kase>0){
cout<<endl;
cout<<"**********************************"<<endl;
cout<<endl;
}
cout<<"Problem #"<<++kase<<endl<<endl;
memset(a,0,sizeof a);
memset(cnt,0,sizeof cnt);
cin >> m;
for (int i = 1;i <= m;i++){
char s[5];int x,y;
cin >> s >> x >> y;
if (s[0]=='H')
a[x][y][0] = 1;
else{
swap(x,y);
a[x][y][1] = 1;
}
}
for (int p = 1;p <= n;p++)
for (int i = 1;i <= n;i++)
for (int j = 1;j <= n;j++)
if (check(i,j,p))
cnt[p]++;
bool none = 1;
for (int i = 1;i <= n;i++){
if (cnt[i]>0) {
none = 0;
cout<<cnt[i]<<" square (s) of size "<<i<<endl;
}
}
if (none) cout<<"No completed squares can be found."<<endl;
}
return 0;
}
【习题 4-2 Uva201】Squares的更多相关文章
- uva201 Squares
Squares A children's board game consists of a square array of dots that contains lines connecting ...
- [刷题]算法竞赛入门经典(第2版) 4-2/UVa201 - Squares
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,20 ms) #include<iostream> #include<cs ...
- 算法习题---4-2正方形(UVa201)
一:题目 判断一个点阵中含有几个正方形(数正方形) 如图例中:有2个边长为1的正方形,1个边长为2的正方形 (一)题目详解 (二)样例输入 4 表示每行每列各有4个顶点 16 表示整个点阵中共有16条 ...
- 【习题 7-6 UVA - 12113】Overlapping Squares
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 先预处理出来一个正方形. 然后每次枚举新加的正方形左上角的坐标就可以. 注意覆盖的规则,控制一下就可以. 然后暴力判断是否相同. 暴 ...
- [LeetCode] Word Squares 单词平方
Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...
- Sharepoint学习笔记—习题系列--70-576习题解析 --索引目录
Sharepoint学习笔记—习题系列--70-576习题解析 为便于查阅,这里整理并列出了70-576习题解析系列的所有问题,有些内容可能会在以后更新. 需要事先申明的是: 1. ...
- 卡通图像变形算法(Moving Least Squares)附源码
本文介绍一种利用移动最小二乘法来实现图像变形的方法,该方法由用户指定图像中的控制点,并通过拖拽控制点来驱动图像变形.假设p为原图像中控制点的位置,q为拖拽后控制点的位置,我们利用移动最小二乘法来为原图 ...
- 《python核心编》程课后习题——第三章
核心编程课后习题——第三章 3-1 由于Python是动态的,解释性的语言,对象的类型和内存都是运行时确定的,所以无需再使用之前对变量名和变量类型进行申明 3-2原因同上,Python的类型检查是在运 ...
- Leetcode: Word Squares && Summary: Another Important Implementation of Trie(Retrieve all the words with a given Prefix)
Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...
随机推荐
- android recovery 系统代码分析 -- 选择进入【转】
本文转载自:http://blog.csdn.net/andyhuabing/article/details/9226569 最近做Recovery的规范及操作指导文档,花了一些时间将流程搞清. An ...
- sqlserver 创建维护计划失败(SQL Server: 14234 错误)自动备份数据库计划
创建维护计划失败(SQL Server: 14234 错误) (2011-06-25 14:44:24) 转载▼ 标签: 杂谈 分类: MSSQL 错误信息:对于 JobStep ' testBak ...
- [HDU4689]Derangement
https://zybuluo.com/ysner/note/1232641 题面 给出\(b_1,b_2,...,b_n\in\{−1,1\}\),求满足\((p_i−i)*b_i<0\)的\ ...
- PCB 奥宝LDI 输出自动改周期检测内容
继续完善奥宝LDI输出,在自动更新周期发现前期梳理不过完善或出些从未考虑到的工艺问题, 今天将更改线路周期检测内容整理如下
- Largest Rectangle in a Histogram(dp)
http://acm.hdu.edu.cn/showproblem.php?pid=1506 题意:给出n个矩形的高度,每个矩形的宽都为1,求相邻的矩形能组合成的最大的矩形的面积. 思路:求出比第i个 ...
- Appium + python - swipe滑屏操作实例
方法一: from appium import webdriverfrom time import sleep descred_caps = { "platformName":&q ...
- django-2的路由层(URLconf)
URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表:你就是以这种方式告诉Django,对于客户端发来的某个URL调用哪一段逻辑代码 ...
- NPOI导出Excel自动计算公式问题
以前用过sheet.ForceFormulaRecalculation = true;当时能够自动计算出来. 今天把模板改了一下(没动公式,但是模板是老板改的,我也不知道他操作了什么),结果就不能自动 ...
- jsp连接MySQL实现登录
1.下载驱动,并把jar包放到Tomcat的lib目录下 下载连接 2.把jar包添加到项目中 3.登录页面 <%@ page language="java" content ...
- Android上UDP组播无法接收数据的问题
最近,想做一个跨平台的局域网的文件传输软件,思路是组播设备信息,TCP连接传输文件.于是进行了一次简单的UDP组播测试,发现Android对于UDP组播接收数据的支持即极为有限. 部分代码如下 pac ...