数长方形

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5258

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

HINT

题意

题解:

看到只有25个棍子,然后我就直接离散化一发,然后离散之后,就感觉就是傻逼题了……

想怎么搞怎么搞

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int g[][];
map<int,int> H1;
map<int,int> H2;
vector<int> x;
vector<int> y;
vector<int> kiss[];
struct node
{
int x1,x2,y1,y2;
}a[];
int main()
{
//test;
int t=read();
for(int cas=;cas<=t;cas++)
{
memset(g,,sizeof(g));
memset(a,,sizeof(a));
H1.clear();
H2.clear();
x.clear();
y.clear();
for(int i=;i<;i++)
kiss[i].clear();
int n=read();
for(int i=;i<n;i++)
{
a[i].x1=read(),a[i].y1=read(),a[i].x2=read(),a[i].y2=read();
if(a[i].x1>a[i].x2)
swap(a[i].x1,a[i].x2);
if(a[i].y1>a[i].y2)
swap(a[i].y1,a[i].y2);
x.push_back(a[i].x1);
x.push_back(a[i].x2);
y.push_back(a[i].y1);
y.push_back(a[i].y2);
}
sort(x.begin(),x.end());
sort(y.begin(),y.end());
x.erase(unique(x.begin(),x.end()),x.end());
y.erase(unique(y.begin(),y.end()),y.end());
for(int i=;i<x.size();i++)
H1[x[i]]=i;
for(int i=;i<y.size();i++)
H2[y[i]]=i;
for(int i=;i<n;i++)
{
a[i].x1=H1[a[i].x1];
a[i].x2=H1[a[i].x2];
a[i].y1=H2[a[i].y1];
a[i].y2=H2[a[i].y2];
//cout<<a[i].x1<<" "<<a[i].y1<<" "<<a[i].x2<<" "<<a[i].y2<<endl;
}
for(int i=;i<n;i++)
if(a[i].x1==a[i].x2)
for(int j=a[i].y1;j<=a[i].y2;j++)
g[a[i].x1][j]=i+; for(int i=;i<n;i++)
if(a[i].y1==a[i].y2)
for(int j=a[i].x1;j<=a[i].x2;j++)
if(g[j][a[i].y1]!=)
kiss[g[j][a[i].y1]].push_back(i+); ll ans=;
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
int flag=;
for(int k=;k<kiss[i].size();k++)
{ for(int m=;m<kiss[j].size();m++)
{
if(kiss[i][k]==kiss[j][m])
{
flag++;
break;
} }
}
ans+=flag*(flag-)/;
}
}
printf("Case #%d:\n",cas);
cout<<ans<<endl;
}
}

hdu 5258 数长方形 离散化的更多相关文章

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

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

  2. 暴力枚举-数长方形(hdu5258)

    数长方形 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  3. Project Euler 85 :Counting rectangles 数长方形

    Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...

  4. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  5. hdu 3436 splay树+离散化*

    Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  6. HDU 5925 Coconuts 【离散化+BFS】 (2016CCPC东北地区大学生程序设计竞赛)

    Coconuts Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  7. HDU 5233 Gunner II 离散化

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5233 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  8. HDU 2084 数塔(动态规划)

    数塔 http://acm.hdu.edu.cn/showproblem.php?pid=2084 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描 ...

  9. hdu 2084 数塔 (简单dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=2084 数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory L ...

随机推荐

  1. HTML和URL比较

    1.录制脚本的基本原则 2.HTML和URL based script介绍 3.选择录制方式原则 4.HTML based script设置

  2. slowhttps安装及使用心得

    运行及安装环境,kali. 到googlecode上下载安装包,cd到安装目录./configure 运行完毕后输入make 结束后make install 简单点就直接apt-get install ...

  3. Win7+xp命令行 一键修改IP、DNS

    这里提供了一个简便方法:(该方法为Win7下的,XP下的见最后一行) 第一步:新建一个txt文件 第二步:在文件中添加如下内容: netsh interface ip set address name ...

  4. 安卓 安装 platforms 的时候报错--访问 url 出错

    强制使用http 访问连接,并在hosts中添加地址,即可 问题描述 使用SDK Manager更新时出现问题Failed to fetch URL https://dl-ssl.google.com ...

  5. Linux 下部署单机 hadoop 测试

    最终运行结果展示: 格式化namenode. 开始测试 显示测试进程 浏览器查看效果展示:(虽然还不清楚是什么意思,但是能看到这个效果已经很开心了) 话不多说,进入主题: 1. 安装 VMwareSt ...

  6. 八皇后问题 --- 递归解法 --- java代码

    八皇后问题是一个以国际象棋为背景的问题:如何能够在 8×8 的国际象棋棋盘上放置八个皇后,使得任何一个皇后都无法直接吃掉其他的皇后?为了达到此目的,任两个皇后都不能处于同一条横行.纵行或斜线上.八皇后 ...

  7. 学习内容:Html5+Axure原型设计

    今日主要在http://www.runoob.com/html/html5-intro.html和http://www.imooc.com/learn/9网站上学习Html的知识,head.title ...

  8. 解决Socket.IO在IE8下触发disconnect时间过长

    本文地址: http://www.cnblogs.com/blackmanba/p/solve-socketIO-IE8-emit-disconnect-too-long.html或者http://f ...

  9. R语言简单入门

    一.运行R语言可以做哪些事? 1.探索性数据分析(将数据绘制图表) 2.统计推断(根据数据进行预测) 3.回归分析(对数据进行拟合分析) 4.机器学习(对数据集进行训练和预测) 5.数据产品开发 二. ...

  10. 基于MapReduce的关系代数运算(1)

    1.选择运算 Map函数:对R中的每个元组t,检测它是否满足条件C,如果满足,则产生一个键值对(t,t) Reduce函数:直接将每个键值对传递到输出即可 2.投影运算 Map函数:对R中的每个元组t ...