数长方形

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 152    Accepted Submission(s): 87

Problem Description
小度熊喜欢玩木棒。一天他在玩木棒的时候,发现一些木棒会形成长方形。小度熊可能是处女座吧,他只会将木棒横竖摆放,这样会形成很多长方形。现在给你一些横竖摆放的木棒,请你帮小度熊数一数形成了多少个长方形。

为了简化题目,一个木棒的端点不会在另一个木棒上,也就是说,木棒的端点不会在长方形上。

 
Input
第一行一个整数T,表示T组数据,不超过100组。

每组数据中,第一行是n,代表有多少个木棒,n不会超过25。接下来n行,每行4个整数x1,y1,x2,y2,代表木棒的坐标,绝对值不超过1000。

所有的木棒都是横竖摆放的,也就是说x1=x2或者y1=y2,没有长为0的木棒。

 
Output
对于每组测试数据,先输出一行

Case #i:

然后输出一个整数,代表有多少个长方形。

 
Sample Input
2
4
3 0 3 3
4 0 4 3
2 1 5 1
2 2 5 2
4
3 0 3 3
4 0 4 3
2 1 5 1
2 2 -5 2
 
Sample Output
Case #1:
1
Case #2:
0
分析:分别把竖条和横条存在col和row数组中,然后两两枚举竖条col[i]和col[j],然后枚举判断row[k]是否横跨col[i]和col[j],若是的话s++,枚举一边row[k]后,此时的矩形个数sum+=s*(s-1)/2;
程序:
 
 #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)的更多相关文章

  1. HDU 5258 数长方形【离散化+暴力】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5258 数长方形 Time Limit: 2000/1000 MS (Java/Others)    Me ...

  2. CCF 201312-4 有趣的数 (数位DP, 状压DP, 组合数学+暴力枚举, 推公式, 矩阵快速幂)

    问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ...

  3. hihoCoder #1179 : 永恒游戏 (暴力枚举)

    题意: 给出一个有n个点的无向图,每个点上有石头数个,现在的游戏规则是,设置某个点A的度数为d,如果A点的石子数大于等于d,则可以从A点给每个邻接点发一个石子.如果游戏可以玩10万次以上,输出INF, ...

  4. [ACM] ZOJ 3816 Generalized Palindromic Number (DFS,暴力枚举)

    Generalized Palindromic Number Time Limit: 2 Seconds      Memory Limit: 65536 KB A number that will ...

  5. HDU - 1248 寒冰王座 数学or暴力枚举

    思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...

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

  7. こだわり者いろはちゃん / Iroha's Obsession (暴力枚举)

    题目链接:http://abc042.contest.atcoder.jp/tasks/arc058_a Time limit : 2sec / Memory limit : 256MB Score ...

  8. CODE FESTIVAL 2017 qual A--B-fLIP(换种想法,暴力枚举)

    个人心得:开始拿着题目还是有点懵逼的,以前做过相同的,不过那是按一个位置行列全都反之,当时也是没有深究.现在在打比赛不得不 重新构思,后面一想把所有的状态都找出来,因为每次确定了已经按下的行和列后,按 ...

  9. HDU 5778 abs (暴力枚举)

    abs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem De ...

随机推荐

  1. JS中基本window.document对象操作以及常用事件!

    一.找到元素 1.document.getELementById("id"):根据id找,最多找一个. var a=document.getELementById("id ...

  2. (IOS)Swift Music 程序分析

    本文主要分享下楼主在学习Swift编程过程中,对GitHub上的一个开源App Swift Music的研究心得. 项目地址:https://github.com/xujiyao123/SwiftMu ...

  3. FW:使用weave管理docker网络

    Posted on 2014-11-12 22:20 feisky 阅读(1761) 评论(0) 编辑 收藏 weave简介 Weave creates a virtual network that ...

  4. CSS控制"标题前增加小图标或编号"

    ---题目前加图片--- p:before { content:url(xxx/xx.png); }//所有p的最前都有一个图标 p.a:after { content:url(xxx/xx.png) ...

  5. 关于android获得设备宽高

    传统的办法: DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(d ...

  6. ArcGIS API for Silverlight 实现修改地图上的工程点位置

    原文:ArcGIS API for Silverlight 实现修改地图上的工程点位置 #region 处理工程点点击编辑相关事件 public Graphic editgraphics = null ...

  7. linux 开机启动设置

    操作系统:Ubuntu12.04硬件环境:HP CQ45        当用户使用sudo apt-get install安装完apache和mysql之后,这些服务默认是开机启动的,但是有的时候需要 ...

  8. 深入浅出WPF(1)—转(http://liutiemeng.blog.51cto.com/120361/91631/)

    深入浅出WPF(1)——什么是WPF 2008-05-15 19:06:00   小序:   Hi,大家好!几乎两个月没有写技术文章了.这两个月,我在学习WPF.回顾一下两个月的学习历程,有两个感觉— ...

  9. Java学习-018-EXCEL 文件写入实例源代码

    众所周知,EXCEL 也是软件测试开发过程中,常用的数据文件导入导出时的类型文件之一,此文主要讲述如何通过 EXCEL 文件中 Sheet 的索引(index)或者 Sheet 名称获取文件中对应 S ...

  10. C# 常用日期函数

    我想知道取的时期是几月.几日,然后做一些统计,上网找了一些方法. --DateTime 数字型 System.DateTime currentTime=new System.DateTime(); 1 ...