hdu 5258 数长方形 离散化
数长方形
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5258
Description
为了简化题目,一个木棒的端点不会在另一个木棒上,也就是说,木棒的端点不会在长方形上
Input
每组数据中,第一行是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 数长方形 离散化的更多相关文章
- HDU 5258 数长方形【离散化+暴力】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5258 数长方形 Time Limit: 2000/1000 MS (Java/Others) Me ...
- 暴力枚举-数长方形(hdu5258)
数长方形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Project Euler 85 :Counting rectangles 数长方形
Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- hdu 3436 splay树+离散化*
Queue-jumpers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- HDU 5925 Coconuts 【离散化+BFS】 (2016CCPC东北地区大学生程序设计竞赛)
Coconuts Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU 5233 Gunner II 离散化
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5233 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- HDU 2084 数塔(动态规划)
数塔 http://acm.hdu.edu.cn/showproblem.php?pid=2084 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描 ...
- hdu 2084 数塔 (简单dp)
http://acm.hdu.edu.cn/showproblem.php?pid=2084 数塔 Time Limit: 1000/1000 MS (Java/Others) Memory L ...
随机推荐
- 15stl模板
1.stack #include<iostream> #include<stdio.h> #include<stack> using namespace std; ...
- html --- canvas --- javascript --- 绘图方法
Canvas元素是HTML5的一部分,允许脚本语言动态渲染位图像. 如有疑问请访问链接:http://javascript.ruanyifeng.com/htmlapi/canvas.html < ...
- Hadoop2的简单安装
前面花了很多时间来介绍hadoop1的安装,随着hadoop的发展,hadoop2的应用也越来越普及,hadoop2解决了hadoop1中的很多问题,比如单点故障,namenode容量小的问题. 我们 ...
- 3Com Network Supervisor与IBM Tivoli NetView两款网管软件操作视频
3Com Network Supervisor与IBM Tivoli NetView两款网管软件操作视频 网管软件必须能够实实在在的给我们带来好处,对于企业网络管理来说,其作用体现在以下几个方面: ...
- HDU 5867 Water problem (模拟)
Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...
- SKAction
[SKAction] 1.Every action is an opaque object that describes a change you want to make to the scene. ...
- HDU4289Control(最大流)
看了这道题,然后重新开始练习自己的刚敲不久的网络流,发现还是难以一遍敲得完整啊,,,,, 调了...遍,改了...遍,测了...遍,交了,,,遍,总算是A了,,不简单啊 然后试着用了其他两种算法EK和 ...
- 手把手教你玩转SOCKET模型之重叠I/O篇(上)
“身为一个初学者,时常能体味到初学者入门的艰辛,所以总是想抽空作点什么来尽我所能的帮助那些需要帮助的人.我也希望大家能把自己的所学和他人一起分享,不要去鄙视别人索取时的贪婪,因为最应该被鄙视的是不肯付 ...
- 汇编语言程序入门实验一:在dos下对用户输入作出应答
汇编语言程序入门实验一:在dos下对用户输入作出应答 1,背景 成功预言了今天要上计算机操作系统上机实验课,昨天预习后,今天的两个上机实验做得很成功.但是也有一些问题.问题1:学校的系统目前是wind ...
- CentOS7 安装 MySQL 5.7.10
卸载冲突的rpm包:rpm -qa|grep mariadbrpm -e --nodeps mariadb-libs-5.5.41-2.el7_0.x86_64 安装:rmp -ivh mysql-c ...