POJ 3168 Barn Expansion (几何+排序)
id=3168">POJ 3168 Barn Expansion
题意:抽象出来就是给出n个矩形的坐标是(左下角和右上角的坐标,矩形的边都是平行x,y轴),问有几个矩形和其它矩形没有接触(仅仅存在边接触或者点接触,不存在有公共面积)。
思路:把边分成两类,平行x轴和平行y轴。对边进行排序。然后for一遍推断是否有相交就可以
AC代码:
- #include <stdio.h>
- #include <vector>
- #include <map>
- #include <set>
- #include <algorithm>
- using namespace std;
- struct node {
- int mark;
- int d,xx,yy;
- node() {}
- node(int _d,int _xx,int _yy,int _mark) {
- d=_d,xx=_xx,yy=_yy,mark=_mark;
- }
- };
- vector<node> sx,sy;
- bool vis[25010];
- bool cmp(node a,node b) {
- if(a.d!=b.d) return a.d<b.d;
- else if(a.xx!=b.xx) return a.xx<b.xx;
- else return a.yy<b.yy;
- }
- int main() {
- int n;
- int i,j,k;
- int a,b,c,d;
- while(scanf("%d",&n)!=EOF) {
- sx.clear();
- sy.clear();
- memset(vis,false,sizeof vis);
- for(i=0; i<n; i++) {
- scanf("%d %d %d %d",&a,&b,&c,&d);
- sy.push_back(node(b,a,c,i));
- sy.push_back(node(d,a,c,i));
- sx.push_back(node(a,b,d,i));
- sx.push_back(node(c,b,d,i));
- }
- int sz1,sz2;
- sz1=sy.size();
- sz2=sx.size();
- sort(sx.begin(),sx.end(),cmp);
- sort(sy.begin(),sy.end(),cmp);
- //竖 y<yy
- int up;
- up=sy[0].yy;
- for(i=1;i<sz1;i++){
- if(sy[i-1].d == sy[i].d){
- if(up >= sy[i].xx){
- vis[sy[i].mark]=vis[sy[i-1].mark]=true;
- }
- }
- else up=sy[i].yy;
- up=max(sy[i].yy,up);
- }
- up=sx[0].yy;
- for(i=1;i<sz2;i++){
- if(sx[i-1].d == sx[i].d){
- if(up >= sx[i].xx){
- vis[sx[i].mark]=vis[sx[i-1].mark]=true;
- }
- }
- else up=sx[i].yy;
- up=max(sx[i].yy,up);
- }
- int ans=0;
- for(i=0;i<n;i++){
- if(!vis[i]) ans++;
- }
- printf("%d\n",ans);
- }
- return 0;
- }
- /*
- 5
- 0 2 2 7
- 3 5 5 8
- 4 2 6 4
- 6 1 8 6
- 0 0 8 1
- 4
- 2 1 3 2
- 2 2 3 3
- 3 3 4 4
- 4 1 5 2
- 9
- 0 0 1 1
- 1 0 2 1
- 2 0 3 1
- 0 1 1 2
- 1 1 2 2
- 2 1 3 2
- 0 2 1 3
- 1 2 2 3
- 2 2 3 3
- 6
- 0 2 2 7
- 3 5 5 8
- 4 2 6 4
- 6 1 8 6
- 0 0 8 1
- 4 5 5 6
- 3
- 1 1 6 6
- 6 2 7 3
- 6 5 8 7
- */
POJ 3168 Barn Expansion (几何+排序)的更多相关文章
- poj 3168 Barn Expansion 几何yy
题链:http://poj.org/problem? id=3168 Barn Expansion Time Limit: 1000MS Memory Limit: 65536K Total Su ...
- poj 3168 Barn Expansion
Barn Expansion Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2465 Accepted: 666 Des ...
- POJ 3168 Barn Expansion (几何基础)
[题目链接] http://poj.org/problem?id=3168 [题目大意] 给出一些矩形,没有相交和包含的情况,只有相切的情况 问有多少个矩形没有相切或者边角重叠 [题解] 我们将所有的 ...
- POJ 3168 排序+扫描
题意: 思路: 我们可以把每个矩形拆成四条线 与x轴平行的放在一起 与y轴平行的放在一起 排个序 判一判有没有交 有交 则说明不可扩张 统计一下 就可以了 处理的姿势很重要 姿势不对毁一生 //By ...
- POJ 2367 (裸拓扑排序)
http://poj.org/problem?id=2367 题意:给你n个数,从第一个数到第n个数,每一行的数字代表排在这个行数的后面的数字,直到0. 这是一个特别裸的拓扑排序的一个题目,拓扑排序我 ...
- poj 3687 Labeling Balls(拓扑排序)
题目:http://poj.org/problem?id=3687题意:n个重量为1~n的球,给定一些编号间的重量比较关系,现在给每个球编号,在符合条件的前提下使得编号小的球重量小.(先保证1号球最轻 ...
- Poj 2371 Questions and answers(排序)
题目链接:http://poj.org/problem?id=2371 思路分析:使用计数排序或其他时间复杂度为O( log N )的排序. 代码如下: #include <iostream&g ...
- [ACM] POJ 3687 Labeling Balls (拓扑排序,反向生成端)
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10161 Accepted: 2810 D ...
- poj 2762(强连通分量+拓扑排序)
题目链接:http://poj.org/problem?id=2762 题意:给出一个有向图,判断任意的两个顶点(u,v)能否从u到达v,或v到达u,即单连通,输出Yes或No. 分析:对于同一个强连 ...
随机推荐
- MySQL —— 如何快速对比数据?
我们在MySql中想要对比下两个不同的实例上的数据并且找出差异,除了主键之外我们还要对比每一个字段,应该怎么做呢? 方案一:写一个程序将两个实例里面的每一行数据都分别取出来对比,但是耗时我们无法估计, ...
- 你所不知道的 CSS 阴影技巧与细节 滚动视差?CSS 不在话下 神奇的选择器 :focus-within 当角色转换为面试官之后 NPOI 教程 - 3.2 打印相关设置 前端XSS相关整理 委托入门案例
你所不知道的 CSS 阴影技巧与细节 关于 CSS 阴影,之前已经有写过一篇,box-shadow 与 filter:drop-shadow 详解及奇技淫巧,介绍了一些关于 box-shadow ...
- C#:向SqlServer数据库中插入imange类型
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServi ...
- C#:设置控件样式(待补充)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- quartz cron表达式在线生成
近期使用了quartz定时器,有感于起cron表达式有点复杂.且无法实时推断定时时间是否正确,因此写了个在线表达式及依据表达式获得前10次运行时间. 訪问地址例如以下:http://cron.g2ro ...
- EM 算法 实例
#coding:utf-8 import math import copy import numpy as np import matplotlib.pyplot as plt isdebug = T ...
- Python 爬虫实例(3)—— 爬取今日头条as cp 算法 解密
关于今日头条的 as cp 算法,只是对时间进行了加密,他们的js代码是压缩处理的,正常格式化就可以了 url = "http://www.toutiao.com/api/pc/feed/& ...
- Object-C中的数字对象
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- HttpOperater-模拟HTTP操作类
using System; using System.IO; using System.Linq; using System.Net; using System.Text; using System. ...
- Mybatis(一):MyBatis配置文件config.xml详解
MyBatis 配置文件基本结构 在使用mybatis框架时,首先导入其对应的jar包,并进行相应的配置,所以得对配置文件的每个参数都得了解.一个完全的mybatis配置文件结构如下: <?xm ...