题目链接:

id=3168">POJ 3168 Barn Expansion

题意:抽象出来就是给出n个矩形的坐标是(左下角和右上角的坐标,矩形的边都是平行x,y轴),问有几个矩形和其它矩形没有接触(仅仅存在边接触或者点接触,不存在有公共面积)。

思路:把边分成两类,平行x轴和平行y轴。对边进行排序。然后for一遍推断是否有相交就可以

AC代码:

  1. #include <stdio.h>
  2. #include <vector>
  3. #include <map>
  4. #include <set>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. struct node {
  9. int mark;
  10. int d,xx,yy;
  11. node() {}
  12. node(int _d,int _xx,int _yy,int _mark) {
  13. d=_d,xx=_xx,yy=_yy,mark=_mark;
  14. }
  15. };
  16.  
  17. vector<node> sx,sy;
  18. bool vis[25010];
  19. bool cmp(node a,node b) {
  20. if(a.d!=b.d) return a.d<b.d;
  21. else if(a.xx!=b.xx) return a.xx<b.xx;
  22. else return a.yy<b.yy;
  23. }
  24.  
  25. int main() {
  26. int n;
  27. int i,j,k;
  28. int a,b,c,d;
  29. while(scanf("%d",&n)!=EOF) {
  30. sx.clear();
  31. sy.clear();
  32. memset(vis,false,sizeof vis);
  33. for(i=0; i<n; i++) {
  34. scanf("%d %d %d %d",&a,&b,&c,&d);
  35. sy.push_back(node(b,a,c,i));
  36. sy.push_back(node(d,a,c,i));
  37. sx.push_back(node(a,b,d,i));
  38. sx.push_back(node(c,b,d,i));
  39. }
  40. int sz1,sz2;
  41. sz1=sy.size();
  42. sz2=sx.size();
  43. sort(sx.begin(),sx.end(),cmp);
  44. sort(sy.begin(),sy.end(),cmp);
  45.  
  46. //竖 y<yy
  47. int up;
  48. up=sy[0].yy;
  49. for(i=1;i<sz1;i++){
  50. if(sy[i-1].d == sy[i].d){
  51. if(up >= sy[i].xx){
  52. vis[sy[i].mark]=vis[sy[i-1].mark]=true;
  53. }
  54. }
  55. else up=sy[i].yy;
  56. up=max(sy[i].yy,up);
  57. }
  58. up=sx[0].yy;
  59. for(i=1;i<sz2;i++){
  60. if(sx[i-1].d == sx[i].d){
  61. if(up >= sx[i].xx){
  62. vis[sx[i].mark]=vis[sx[i-1].mark]=true;
  63. }
  64. }
  65. else up=sx[i].yy;
  66. up=max(sx[i].yy,up);
  67. }
  68. int ans=0;
  69. for(i=0;i<n;i++){
  70. if(!vis[i]) ans++;
  71. }
  72. printf("%d\n",ans);
  73. }
  74. return 0;
  75. }
  76. /*
  77. 5
  78. 0 2 2 7
  79. 3 5 5 8
  80. 4 2 6 4
  81. 6 1 8 6
  82. 0 0 8 1
  83.  
  84. 4
  85. 2 1 3 2
  86. 2 2 3 3
  87. 3 3 4 4
  88. 4 1 5 2
  89.  
  90. 9
  91. 0 0 1 1
  92. 1 0 2 1
  93. 2 0 3 1
  94. 0 1 1 2
  95. 1 1 2 2
  96. 2 1 3 2
  97. 0 2 1 3
  98. 1 2 2 3
  99. 2 2 3 3
  100.  
  101. 6
  102. 0 2 2 7
  103. 3 5 5 8
  104. 4 2 6 4
  105. 6 1 8 6
  106. 0 0 8 1
  107. 4 5 5 6
  108.  
  109. 3
  110. 1 1 6 6
  111. 6 2 7 3
  112. 6 5 8 7
  113. */

POJ 3168 Barn Expansion (几何+排序)的更多相关文章

  1. poj 3168 Barn Expansion 几何yy

    题链:http://poj.org/problem? id=3168 Barn Expansion Time Limit: 1000MS   Memory Limit: 65536K Total Su ...

  2. poj 3168 Barn Expansion

    Barn Expansion Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2465   Accepted: 666 Des ...

  3. POJ 3168 Barn Expansion (几何基础)

    [题目链接] http://poj.org/problem?id=3168 [题目大意] 给出一些矩形,没有相交和包含的情况,只有相切的情况 问有多少个矩形没有相切或者边角重叠 [题解] 我们将所有的 ...

  4. POJ 3168 排序+扫描

    题意: 思路: 我们可以把每个矩形拆成四条线 与x轴平行的放在一起 与y轴平行的放在一起 排个序 判一判有没有交 有交 则说明不可扩张 统计一下 就可以了 处理的姿势很重要 姿势不对毁一生 //By ...

  5. POJ 2367 (裸拓扑排序)

    http://poj.org/problem?id=2367 题意:给你n个数,从第一个数到第n个数,每一行的数字代表排在这个行数的后面的数字,直到0. 这是一个特别裸的拓扑排序的一个题目,拓扑排序我 ...

  6. poj 3687 Labeling Balls(拓扑排序)

    题目:http://poj.org/problem?id=3687题意:n个重量为1~n的球,给定一些编号间的重量比较关系,现在给每个球编号,在符合条件的前提下使得编号小的球重量小.(先保证1号球最轻 ...

  7. Poj 2371 Questions and answers(排序)

    题目链接:http://poj.org/problem?id=2371 思路分析:使用计数排序或其他时间复杂度为O( log N )的排序. 代码如下: #include <iostream&g ...

  8. [ACM] POJ 3687 Labeling Balls (拓扑排序,反向生成端)

    Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10161   Accepted: 2810 D ...

  9. poj 2762(强连通分量+拓扑排序)

    题目链接:http://poj.org/problem?id=2762 题意:给出一个有向图,判断任意的两个顶点(u,v)能否从u到达v,或v到达u,即单连通,输出Yes或No. 分析:对于同一个强连 ...

随机推荐

  1. MySQL —— 如何快速对比数据?

    我们在MySql中想要对比下两个不同的实例上的数据并且找出差异,除了主键之外我们还要对比每一个字段,应该怎么做呢? 方案一:写一个程序将两个实例里面的每一行数据都分别取出来对比,但是耗时我们无法估计, ...

  2. 你所不知道的 CSS 阴影技巧与细节 滚动视差?CSS 不在话下 神奇的选择器 :focus-within 当角色转换为面试官之后 NPOI 教程 - 3.2 打印相关设置 前端XSS相关整理 委托入门案例

    你所不知道的 CSS 阴影技巧与细节   关于 CSS 阴影,之前已经有写过一篇,box-shadow 与 filter:drop-shadow 详解及奇技淫巧,介绍了一些关于 box-shadow  ...

  3. C#:向SqlServer数据库中插入imange类型

    using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServi ...

  4. C#:设置控件样式(待补充)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  5. quartz cron表达式在线生成

    近期使用了quartz定时器,有感于起cron表达式有点复杂.且无法实时推断定时时间是否正确,因此写了个在线表达式及依据表达式获得前10次运行时间. 訪问地址例如以下:http://cron.g2ro ...

  6. EM 算法 实例

    #coding:utf-8 import math import copy import numpy as np import matplotlib.pyplot as plt isdebug = T ...

  7. Python 爬虫实例(3)—— 爬取今日头条as cp 算法 解密

    关于今日头条的 as cp 算法,只是对时间进行了加密,他们的js代码是压缩处理的,正常格式化就可以了 url = "http://www.toutiao.com/api/pc/feed/& ...

  8. Object-C中的数字对象

    #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...

  9. HttpOperater-模拟HTTP操作类

    using System; using System.IO; using System.Linq; using System.Net; using System.Text; using System. ...

  10. Mybatis(一):MyBatis配置文件config.xml详解

    MyBatis 配置文件基本结构 在使用mybatis框架时,首先导入其对应的jar包,并进行相应的配置,所以得对配置文件的每个参数都得了解.一个完全的mybatis配置文件结构如下: <?xm ...