暴力枚举-数长方形(hdu5258)
数长方形
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 152 Accepted Submission(s): 87
为了简化题目,一个木棒的端点不会在另一个木棒上,也就是说,木棒的端点不会在长方形上。
每组数据中,第一行是n,代表有多少个木棒,n不会超过25。接下来n行,每行4个整数x1,y1,x2,y2,代表木棒的坐标,绝对值不超过1000。
所有的木棒都是横竖摆放的,也就是说x1=x2或者y1=y2,没有长为0的木棒。
Case #i:
然后输出一个整数,代表有多少个长方形。
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#include"algorithm"
#include"queue"
#include"math.h"
#include"iostream"
#include"vector"
#define M 100009
#define inf 0x3f3f3f3f
#define eps 1e-9
#define PI acos(-1.0)
#include"map"
#include"vector"
#include"set"
#include"string"
#include"stack"
#define LL __int64
using namespace std;
struct node
{
int x,y;
node(){}
node(int x,int y)
{
this->x=x;
this->y=y;
}
};
struct line
{
node s,e;
}col[M],row[M];
int cmp(line a,line b)
{
return a.s.x<b.s.x;
}
int ok(line a,line b,line c)
{
if(c.s.x<=a.s.x
&&c.e.x>=b.s.x
&&c.s.y<=min(a.s.y,b.s.y)
&&c.s.y>=max(a.e.y,b.e.y))
return ;
return ;
}
int main()
{
int T,kk=;
cin>>T;
while(T--)
{
int n;
scanf("%d",&n);
int x1,x2,y1,y2;
int col_k=;
int row_k=;
for(int i=;i<=n;i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1==x2)
{
++col_k;
col[col_k].s=node(x1,max(y1,y2));
col[col_k].e=node(x1,min(y1,y2));
}
else if(y1==y2)
{
++row_k;
row[row_k].s=node(min(x1,x2),y1);
row[row_k].e=node(max(x1,x2),y1);
}
}
sort(col+,col+col_k+,cmp);
int sum=;
for(int i=;i<=col_k;i++)
{
for(int j=i+;j<=col_k;j++)
{
int s=;
for(int k=;k<=row_k;k++)
{
if(ok(col[i],col[j],row[k]))
s++;
}
s--;
if(s>=)
{
s=s*(s+)/;
sum+=s;
}
}
}
printf("Case #%d:\n",kk++);
printf("%d\n",sum);
}
return ;
}
/*
23
6
1 0 1 5
5 0 5 5
0 4 6 4
0 2 6 2
0 1 6 1
3 0 3 3 2
0 0 0 5
6 0 6 6 7
0 1 100 1
0 3 100 3
0 95 100 95
0 97 100 97
3 0 3 10
3 90 3 100
90 0 90 110 10
0 1 100 1
0 2 100 2
0 3 100 3
0 4 100 4
0 5 100 5
10 0 10 110
11 0 11 110
12 0 12 110
13 0 13 110
15 0 15 110 */
暴力枚举-数长方形(hdu5258)的更多相关文章
- HDU 5258 数长方形【离散化+暴力】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5258 数长方形 Time Limit: 2000/1000 MS (Java/Others) Me ...
- CCF 201312-4 有趣的数 (数位DP, 状压DP, 组合数学+暴力枚举, 推公式, 矩阵快速幂)
问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ...
- hihoCoder #1179 : 永恒游戏 (暴力枚举)
题意: 给出一个有n个点的无向图,每个点上有石头数个,现在的游戏规则是,设置某个点A的度数为d,如果A点的石子数大于等于d,则可以从A点给每个邻接点发一个石子.如果游戏可以玩10万次以上,输出INF, ...
- [ACM] ZOJ 3816 Generalized Palindromic Number (DFS,暴力枚举)
Generalized Palindromic Number Time Limit: 2 Seconds Memory Limit: 65536 KB A number that will ...
- HDU - 1248 寒冰王座 数学or暴力枚举
思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...
- Gym 101194L / UVALive 7908 - World Cup - [三进制状压暴力枚举][2016 EC-Final Problem L]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
- こだわり者いろはちゃん / Iroha's Obsession (暴力枚举)
题目链接:http://abc042.contest.atcoder.jp/tasks/arc058_a Time limit : 2sec / Memory limit : 256MB Score ...
- CODE FESTIVAL 2017 qual A--B-fLIP(换种想法,暴力枚举)
个人心得:开始拿着题目还是有点懵逼的,以前做过相同的,不过那是按一个位置行列全都反之,当时也是没有深究.现在在打比赛不得不 重新构思,后面一想把所有的状态都找出来,因为每次确定了已经按下的行和列后,按 ...
- HDU 5778 abs (暴力枚举)
abs Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem De ...
随机推荐
- go liteIDE
go liteIDE 1 COMM FILE package pricetable import ( "fmt" "math" "os" ...
- 删除win7中的库/收藏夹/家庭组/网络
通过修改注册表删除库/收藏夹/家庭组/网络(还是不习惯库的这种管理方式, 导航里面又太占地方) 库:[HKEY_CLASSES_ROOT\CLSID\{031E4825-7B94-4dc3-B131- ...
- 使用JavaScript创建我的分页
把下面的方法放到一个js文件,页面引用他就行了 JavaScript function PageList(PageSize, PageIndex, TotalCount, ParList) { $(& ...
- python 之 utf-8编码的秘密
python3的默认编码方案是utf-8编码,看了些资料,来做总结. 要说utf-8,就要说说unicode,要说unicode,就要说ASCII,我们还是慢慢来. 1.ASCII ASCII编码最初 ...
- IE下载时提示无法下载,重试后成功
// Add Excel as content type and attachment Response.ContentType = “application/vnd.ms-excel”; Res ...
- SQL2000的Enterprise Edition和Developer Edition有什么区别
1.SQL Server 2000 Enterprise Edition(企业版) 该版本具有强大的可伸缩性和可靠性,可作为大型WEB站点.企业联机事务处理(OLTP)以及数据仓库系统等数据库产品的服 ...
- Python开发【第二章】:Python的数据类型
基本数据类型 一.整型 如: 18.73.84 整型具备如下功能: class int(object): """ int(x=0) -> int or long i ...
- SSH原理与运用(一)和(二):远程登录 RSA算法原理(一)和(二)
SSH原理与运用(一)和(二):远程登录 RSA算法原理(一)和(二) http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html ht ...
- iOS网络相关零散知识总结
iOS网络相关零散知识总结 1. URL和HTTP知识 (1) URL的全称是Uniform Resource Locator(统一资源定位符). URL的基本格式 = 协议://主机地址/路径 ...
- OGRFeature的DestroyFeature方法
Ogr的销毁DestroyFeature方法: void OGRFeature::DestroyFeature( OGRFeature *poFeature ) { delete poFeature; ...