数长方形

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个棍子,然后我就直接离散化一发,然后离散之后,就感觉就是傻逼题了……

想怎么搞怎么搞

代码:

  1. //qscqesze
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <ctime>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <set>
  9. #include <vector>
  10. #include <sstream>
  11. #include <queue>
  12. #include <typeinfo>
  13. #include <fstream>
  14. #include <map>
  15. #include <stack>
  16. typedef long long ll;
  17. using namespace std;
  18. //freopen("D.in","r",stdin);
  19. //freopen("D.out","w",stdout);
  20. #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
  21. #define test freopen("test.txt","r",stdin)
  22. #define maxn 2000001
  23. #define mod 10007
  24. #define eps 1e-9
  25. int Num;
  26. char CH[];
  27. const int inf=0x3f3f3f3f;
  28. const ll infll = 0x3f3f3f3f3f3f3f3fLL;
  29. inline ll read()
  30. {
  31. ll x=,f=;char ch=getchar();
  32. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  33. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  34. return x*f;
  35. }
  36. inline void P(int x)
  37. {
  38. Num=;if(!x){putchar('');puts("");return;}
  39. while(x>)CH[++Num]=x%,x/=;
  40. while(Num)putchar(CH[Num--]+);
  41. puts("");
  42. }
  43. //**************************************************************************************
  44.  
  45. int g[][];
  46. map<int,int> H1;
  47. map<int,int> H2;
  48. vector<int> x;
  49. vector<int> y;
  50. vector<int> kiss[];
  51. struct node
  52. {
  53. int x1,x2,y1,y2;
  54. }a[];
  55. int main()
  56. {
  57. //test;
  58. int t=read();
  59. for(int cas=;cas<=t;cas++)
  60. {
  61. memset(g,,sizeof(g));
  62. memset(a,,sizeof(a));
  63. H1.clear();
  64. H2.clear();
  65. x.clear();
  66. y.clear();
  67. for(int i=;i<;i++)
  68. kiss[i].clear();
  69. int n=read();
  70. for(int i=;i<n;i++)
  71. {
  72. a[i].x1=read(),a[i].y1=read(),a[i].x2=read(),a[i].y2=read();
  73. if(a[i].x1>a[i].x2)
  74. swap(a[i].x1,a[i].x2);
  75. if(a[i].y1>a[i].y2)
  76. swap(a[i].y1,a[i].y2);
  77. x.push_back(a[i].x1);
  78. x.push_back(a[i].x2);
  79. y.push_back(a[i].y1);
  80. y.push_back(a[i].y2);
  81. }
  82. sort(x.begin(),x.end());
  83. sort(y.begin(),y.end());
  84. x.erase(unique(x.begin(),x.end()),x.end());
  85. y.erase(unique(y.begin(),y.end()),y.end());
  86. for(int i=;i<x.size();i++)
  87. H1[x[i]]=i;
  88. for(int i=;i<y.size();i++)
  89. H2[y[i]]=i;
  90. for(int i=;i<n;i++)
  91. {
  92. a[i].x1=H1[a[i].x1];
  93. a[i].x2=H1[a[i].x2];
  94. a[i].y1=H2[a[i].y1];
  95. a[i].y2=H2[a[i].y2];
  96. //cout<<a[i].x1<<" "<<a[i].y1<<" "<<a[i].x2<<" "<<a[i].y2<<endl;
  97. }
  98. for(int i=;i<n;i++)
  99. if(a[i].x1==a[i].x2)
  100. for(int j=a[i].y1;j<=a[i].y2;j++)
  101. g[a[i].x1][j]=i+;
  102.  
  103. for(int i=;i<n;i++)
  104. if(a[i].y1==a[i].y2)
  105. for(int j=a[i].x1;j<=a[i].x2;j++)
  106. if(g[j][a[i].y1]!=)
  107. kiss[g[j][a[i].y1]].push_back(i+);
  108.  
  109. ll ans=;
  110. for(int i=;i<=n;i++)
  111. {
  112. for(int j=i+;j<=n;j++)
  113. {
  114. int flag=;
  115. for(int k=;k<kiss[i].size();k++)
  116. {
  117.  
  118. for(int m=;m<kiss[j].size();m++)
  119. {
  120. if(kiss[i][k]==kiss[j][m])
  121. {
  122. flag++;
  123. break;
  124. }
  125.  
  126. }
  127. }
  128. ans+=flag*(flag-)/;
  129. }
  130. }
  131. printf("Case #%d:\n",cas);
  132. cout<<ans<<endl;
  133. }
  134. }

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. CXF之九 WS-Security

    Webservice 的安全 Webservice为作为方便的服务被用广大领域使用的同时,也成为了黑客们的美食.在这里,本文将就目前对Webservice安全所能做的改进做简单介绍.在Webservi ...

  2. cocos2d-x 全面总结--字体描边和制作阴影

    关于字体描边的实现,不考虑效果和效率的话,是有三种方式: ① 利用CCLabelTTF制作文字描边和阴影效果 ② 利用CCRenderTexture渲染文理的方式生成带有描边效果的文字 ③ 利用sha ...

  3. Netmask v. Address Prefix Length

    Netmask Address Prefix Length Hosts / Class C's / Class B's / Class A's (Class C) / / , / , / , / , ...

  4. Python线程

    原文出处: AstralWind 1. 线程基础 1.1. 线程状态 线程有5种状态,状态转换的过程如下图所示: 1.2. 线程同步(锁) 多线程的优势在于可以同时运行多个任务(至少感觉起来是这样). ...

  5. IOS自动布局

    参考资料 https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AutolayoutPG/Vi ...

  6. MySQL 5.5 服务器变量详解二(转)

    add by zhj:在MySQL5.6中对一些参数有增删改,详见http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html ...

  7. NetBeans IDE 7.4 Beta版本build JavaFX时生成的可执行jar包执行时找不到依赖的jar包

    现象,执行时抛出java.lang.ClassNotFoundException异常: Executing E:\secondegg\secondegg-reversi\dist\run8022211 ...

  8. quora 中有关angular与emberjs的精彩辩论

    原贴地址,要注册才能看,这里只有国人翻译的一部分内容 本文源自于Quora网站的一个问题,作者称最近一直在为一个新的Rails项目寻找一个JavaScript框架,通过筛选,最终纠结于Angular. ...

  9. xml velocity模板

    . <?xml version="1.0" encoding="GBK"?> <PACKET type="REQUEST" ...

  10. centos安装lxml和pyspider

    yum -y install --nogpgcheck python34u-devel.x86_64 yum -y install libcurl-devel yum -y install libxs ...