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 ... 
随机推荐
- Android 应用启动速度优化
			现在很多的应用一开始点击的时候总会出现黑屏或者白屏,甚至前段时间微信也有同样的问题.其实白屏或者黑屏还是一些其他的东西,都是因为Android 主题的问题,只要自己自定义一个启动主题,问题完美解决. ... 
- 实现3D摄像机缓冲系统的一些思考
			最近需要模拟红侠乔伊的镜头运用.这东西初看简单,实际还是很需要功夫的.关键不是程序技术如何(就一个摄像机),而是分析其轨迹和追踪点规律.其实就是一个3D空间中的缓冲系统.你如何确定都有什么参数,这么多 ... 
- 【树莓派2B倒腾日志】之安装系统及配置
			15号树莓派到手到现在,折腾了也有一小周,自己摸索着,装了系统,登上SSH,更新了源,连了VNC,换上wifi,亮了小灯.再到今天捣鼓了下数码管,回头想想,该写个日志记录一下这一周的所得,自己总结也方 ... 
- 求职基础复习之冒泡排序c++版
			代码中在第一层循环中增加一个bool值,是为了防止在排序完成后还继续无谓的比较,最多会有(n-1)*(n-2)/2次循环. #include<iostream> using namespa ... 
- python 数字和字符串转换问题
			一.python中字符串转换成数字 (1)import string tt='555' ts=string.atoi(tt) ts即为tt转换成的数字 转换为浮点数 string.atof(tt) ( ... 
- Arduino uno R3 ISP刷Rootloader for arduino pro mini
			找了好久才发现的,好东西.介绍怎么使用uno对mini 刷Rootloader **SOLUTION** Reinstall the Arduino Pro Mini Bootloader using ... 
- Hibernate中openSession() 与 getCurrentSession()的区别
			1 getCurrentSession创建的session会和绑定到当前线程,而openSession每次创建新的session. 2 getCurrentSession创建的线程会在事务回滚或事物提 ... 
- geeksforgeeks@ Largest Number formed from an Array
			http://www.practice.geeksforgeeks.org/problem-page.php?pid=380 Largest Number formed from an Array G ... 
- openstack neutron网络主机节点网口配置 liberty版本之前的
- php--opp--2.什么是类,什么是对象,类和对象这间的关系
			类的概念:类是具有相同属性和服务的一组对象的集合.它为属于该类的所有对象提供了统一的抽象描述,其内部包括属性和服务两个主要部分.在面向对象的编程语言中,类是一个独立的程序单位,它应该有一个类名并包括属 ... 
