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 ...
随机推荐
- memcache、memcached、groupcache的区别
对PHP语言来说,PHP使用memcache有两个模块,分别叫memcache和memcached,他们的区别看下表: 参考:http://hi.baidu.com/tony_wd/item/605e ...
- js String方法集合
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String//返回对应索引的字符 ...
- textBox只能输入汉字
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar > 0 && ...
- 任务(Tasks)
在Eclipse中用TODO标签管理任务,利用这个功能可以方便地将项目中一些需要处理的任务记录下来.我们可以通过在java注释里添加任务标签来标记一个任务,任务可以通过Tasks(任务)视图来察看. ...
- 文本框的onchange事件,如何兼容各大浏览器
在项目中经常会遇到对用户输入的数据进行实时校验,而不是等文本框失去焦点或用户手动点击校验. 首先分析下在哪些情况下文本框会产生change事件. 1.用户通过键盘入正常字符时: 2.用户通过键盘输入非 ...
- AudioManager --- generateAudioSessionId
AudioManager中的generateAudioSessionId方法介绍: 1.方法声明 pubilc void generateAudioSessionId(); 2.API描述 返回一个不 ...
- Linux_搜文件
Linux 下搜文件, 通常先用 whereis 或 locate ,如果找不到,才以 find 搜寻!因为 whereis 与 locate 是利用数据库来搜寻数据,省时间! <<鸟哥的 ...
- WebService调用一对多关联关系时出现 死循环:A cycle is detected in...
通过WebService调用一对多关联关系时引起的问题:A cycle is detected in the object graph 具体异常信息: org.apache.cxf.intercept ...
- [LeetCode] #167# Two Sum II : 数组/二分查找/双指针
一. 题目 1. Two Sum II Given an array of integers that is already sorted in ascending order, find two n ...
- 基于jquery的表格动态创建,自动绑定,自动获取值
最近刚加入GUT项目,学习了很多其他同事写的代码,感觉受益匪浅. 在GUT项目中,经常会碰到这样一个问题:动态生成表格,包括从数据库中读取数据,并绑定在表格中,以及从在页面上通过jQuery新增删除表 ...