【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

注意那个星号的数量。。。
然后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的更多相关文章

  1. uva201 Squares

     Squares  A children's board game consists of a square array of dots that contains lines connecting ...

  2. [刷题]算法竞赛入门经典(第2版) 4-2/UVa201 - Squares

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,20 ms) #include<iostream> #include<cs ...

  3. 算法习题---4-2正方形(UVa201)

    一:题目 判断一个点阵中含有几个正方形(数正方形) 如图例中:有2个边长为1的正方形,1个边长为2的正方形 (一)题目详解 (二)样例输入 4 表示每行每列各有4个顶点 16 表示整个点阵中共有16条 ...

  4. 【习题 7-6 UVA - 12113】Overlapping Squares

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 先预处理出来一个正方形. 然后每次枚举新加的正方形左上角的坐标就可以. 注意覆盖的规则,控制一下就可以. 然后暴力判断是否相同. 暴 ...

  5. [LeetCode] Word Squares 单词平方

    Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...

  6. Sharepoint学习笔记—习题系列--70-576习题解析 --索引目录

        Sharepoint学习笔记—习题系列--70-576习题解析  为便于查阅,这里整理并列出了70-576习题解析系列的所有问题,有些内容可能会在以后更新. 需要事先申明的是:     1. ...

  7. 卡通图像变形算法(Moving Least Squares)附源码

    本文介绍一种利用移动最小二乘法来实现图像变形的方法,该方法由用户指定图像中的控制点,并通过拖拽控制点来驱动图像变形.假设p为原图像中控制点的位置,q为拖拽后控制点的位置,我们利用移动最小二乘法来为原图 ...

  8. 《python核心编》程课后习题——第三章

    核心编程课后习题——第三章 3-1 由于Python是动态的,解释性的语言,对象的类型和内存都是运行时确定的,所以无需再使用之前对变量名和变量类型进行申明 3-2原因同上,Python的类型检查是在运 ...

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

随机推荐

  1. It&#39;s not a Bug, It&#39;s a Feature! (poj 1482 最短路SPFA+隐式图+位运算)

    Language: Default It's not a Bug, It's a Feature! Time Limit: 5000MS   Memory Limit: 30000K Total Su ...

  2. Java类集-list

    Collection 子接口: ArrayList是List 接口和Collection接口的一个子类,用于实例化两种接口 package leiji; import java.util.ArrayL ...

  3. BZOJ 1787: [Ahoi2008]Meet 紧急集合 LCA

    1787: [Ahoi2008]Meet 紧急集合 Description Input Output Sample Input 6 4 1 2 2 3 2 4 4 5 5 6 4 5 6 6 3 1 ...

  4. hdu 1242(BFS+优先队列)

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  5. uva1084

    状压dp+凸包 并没有看出来凸包的性质 首先答案一定在凸包上,然后每个凸包的角加起来是一个圆,那么就相当于凸包周长加一个圆了.然后预处理,再状压dp计算即可. #include<bits/std ...

  6. Spark深入之RDD

    目录 Part III. Low-Level APIs Resilient Distributed Datasets (RDDs) 1.介绍 2.RDD代码 3.KV RDD 4.RDD Join A ...

  7. Python入门 不必自己造轮子

    操作list list切片 字符串的分割 字符串的索引和切片 读文件 f = file('data.txt') data = f.read() print data f.close() 写文件 dat ...

  8. 10.Flask-上下文

    1.1.local线程隔离对象 不用local对象的情况 from threading import Thread request = ' class MyThread(Thread): def ru ...

  9. POJ 1659 Havel-Hakimi定理

    关于题意和Havel-Hakimi定理,可以看看http://blog.csdn.net/wangjian8006/article/details/7974845 讲得挺好的. 我就直接粘过来了 [ ...

  10. pinpoint 磁盘不足的坑

    观察 pinpoint hbase 数据存储目录default中各个表的大小 TraceV2 15G ApplicationTraceIndex 15G major_compact的操作目的 合并文件 ...