暴力枚举-数长方形(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 ...
随机推荐
- phpexcel 读取数据
最近公司做一个客户导入会员的功能,以前导入都是使用csv格式导入的,但是客户反应问题挺多的,普遍是乱码(由于各种系统各种环境可能引起编码问题).最近想着就把这个导入完全改成excel导入,就研究了下p ...
- Liunx 下使用cmake
参考 http://blog.chinaunix.net/uid-28458801-id-3501768.html http://www.ibm.com/developerworks/cn/linux ...
- BLE-NRF51822教程-RSSI获取
当手机和设备连接上后,设备端可以通过获取RSSI,在一定程度上判断手机离设备的相对距离的远近. 获取函数很简单直接调用sd_ble_gap_rssi_get 接口函数就行了,传入连接句柄和buff就能 ...
- lifecycle of opensource products--x86-64
x86是指intel的开发的一种32位指令集,从386开始时代开始的,一直沿用至今,是一种cisc指令集,所有intel早期的cpu,amd早期的cpu都支持这种指令集,ntel官方文档里面称为“IA ...
- Android源码剖析之Framework层实战版(Ams管理Activity启动)
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 讲到实战,就不得不拿两个例子来说明,本篇想拿的是应用最广泛的两个:Ams和Wms,一个管理activ ...
- Struts Upload上传文件
1.Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.te ...
- Mysql 按行dump出数据
mysqldump -u${user} -p${passwd} --skip-extended-insert --database ${dbname} --table ${tablename} > ...
- C++字符数字的编码(Encode)与解码(Decode)
在日常应用中,我们常用结构体或者类来存储一条信息,这种方式很方便,但是不利于数据的传输.例如在网络编程中,我们需要将结构中的数据转化为字节流才能进行传输,我们可以利用memcpy强行将结构化的数据转化 ...
- PHP实现QQ第三方登录
PHP实现QQ第三方登录 学习之前,请大家先看一下oAuth协议. 首先呢,我们进入QQ互联的官方网站 http://connect.qq.com登入我们自己的QQ号,没有QQ号的小伙伴可以忽略本篇博 ...
- 【转载】拒绝平庸——浅谈WEB登录页面设计
用户活跃度是检验产品成功与否的重要指标之一,传统行业的商家极为重视门面的装潢,因为一个好的门面可以聚集人气,招揽更多的顾客.古时候的大户人家院子门口的石狮子或其他的摆件的摆放极为讲究,有一定的风水学说 ...