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 ...
随机推荐
- CXF之九 WS-Security
Webservice 的安全 Webservice为作为方便的服务被用广大领域使用的同时,也成为了黑客们的美食.在这里,本文将就目前对Webservice安全所能做的改进做简单介绍.在Webservi ...
- cocos2d-x 全面总结--字体描边和制作阴影
关于字体描边的实现,不考虑效果和效率的话,是有三种方式: ① 利用CCLabelTTF制作文字描边和阴影效果 ② 利用CCRenderTexture渲染文理的方式生成带有描边效果的文字 ③ 利用sha ...
- Netmask v. Address Prefix Length
Netmask Address Prefix Length Hosts / Class C's / Class B's / Class A's (Class C) / / , / , / , / , ...
- Python线程
原文出处: AstralWind 1. 线程基础 1.1. 线程状态 线程有5种状态,状态转换的过程如下图所示: 1.2. 线程同步(锁) 多线程的优势在于可以同时运行多个任务(至少感觉起来是这样). ...
- IOS自动布局
参考资料 https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AutolayoutPG/Vi ...
- MySQL 5.5 服务器变量详解二(转)
add by zhj:在MySQL5.6中对一些参数有增删改,详见http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html ...
- NetBeans IDE 7.4 Beta版本build JavaFX时生成的可执行jar包执行时找不到依赖的jar包
现象,执行时抛出java.lang.ClassNotFoundException异常: Executing E:\secondegg\secondegg-reversi\dist\run8022211 ...
- quora 中有关angular与emberjs的精彩辩论
原贴地址,要注册才能看,这里只有国人翻译的一部分内容 本文源自于Quora网站的一个问题,作者称最近一直在为一个新的Rails项目寻找一个JavaScript框架,通过筛选,最终纠结于Angular. ...
- xml velocity模板
. <?xml version="1.0" encoding="GBK"?> <PACKET type="REQUEST" ...
- centos安装lxml和pyspider
yum -y install --nogpgcheck python34u-devel.x86_64 yum -y install libcurl-devel yum -y install libxs ...