代码:

#include<iostream>
#include<fstream>using namespace std;struct e{int l,r;bool isa;
};e tree[80001];
int n;struct f{int num,s,l;
};f b[20001];int c[10001][2];int cmp(const void *a,const void *b){f *s=(f*)a;f *t=(f*)b;return s->l-t->l;
}void build(int s,int t,int p){tree[p].l=s;tree[p].r=t;tree[p].isa=0;if(s==t) return;int k=(s+t)>>1;build(s,k,p*2);build(k+1,t,2*p+1);
}int update(int s,int t,int p){int i,j,k;if(s<=tree[p].l&&tree[p].r<=t){if(tree[p].isa==1) return 0;else{tree[p].isa=1;return 1;}}if(tree[p].isa) return 0;if(t<=tree[2*p].r){i= update(s,t,p*2);if(tree[2*p].isa&&tree[2*p+1].isa)tree[p].isa=1;return i;}elseif(s>=tree[2*p+1].l){ i= update(s,t,p*2+1);if(tree[2*p].isa&&tree[2*p+1].isa)tree[p].isa=1;return i;  }else{i=update(s,t,p*2);j=update(s,t,p*2+1);if(tree[2*p].isa&&tree[2*p+1].isa)tree[p].isa=1;if(i||j) return 1;return 0;}}void read(){
//  ifstream cin("in.txt");int i,j,k;int cas;cin>>cas;while(cas--){cin>>n;for(i=0;i<n;i++){cin>>b[2*i].l>>b[2*i+1].l;b[2*i].num=i+1;b[2*i].s=0;b[2*i+1].num=i+1;b[2*i+1].s=1;}qsort(b,2*n,sizeof(f),cmp);j=1;c[b[0].num][b[0].s]=1;for(i=1;i<2*n;i++){if(b[i].l!=b[i-1].l) j++;c[b[i].num][b[i].s]=j;}build(1,j,1);int ans=0;for(i=n;i>=1;i--){if(c[i][0]>c[i][1]) swap(c[i][0],c[i][1]);ans+=update(c[i][0],c[i][1],1);}cout<<ans<<endl;}
}int main(){read();return 0;
}

转载于:https://www.cnblogs.com/zhaozhe/archive/2011/05/16/2047509.html

poj 2528_2相关推荐

  1. POJ 3268 D-Silver Cow Party

    http://poj.org/problem?id=3268 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

  2. poj 2559 Largest Rectangle in a Histogram 栈

    // poj 2559 Largest Rectangle in a Histogram 栈 // // n个矩形排在一块,不同的高度,让你求最大的矩形的面积(矩形紧挨在一起) // // 这道题用的 ...

  3. POJ 2528 Mayor's posters(线段树)

    题目大意 贴海报.每张海报的高度都是一样的,唯独宽度不一样.每张海报只能占用整数倍的单位线段长度,贴了 n(n<=10000) 张海报之后,有几张能够看见(有一个角能看见这张海报也算被看见了)? ...

  4. POJ 2226 Muddy Fields 最小点覆盖+加建图(好题)

    题目链接 题目一看就是最小点覆盖,这道题与POJ - 3041 算是一类题,但是3041算是一道十分裸的,因为删除的是整行或者整列,所以图其实是现成的,但是本题的难点就在如何建图. 思路:首先还是尽量 ...

  5. poj 2681 字符串

    http://poj.org/problem?id=2681 给你任意长度的字符串,找出两串字符中不相同的字符个数(总数) #include<string> #include<cst ...

  6. (区间dp 或 记忆化搜素 )Brackets -- POJ -- 2955

    http://poj.org/problem?id=2955 Description We give the following inductive definition of a "reg ...

  7. POJ 2586 Y2K Accounting Bug(贪心)

    题目连接:http://poj.org/problem?id=2586 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D.公司每五个月进行一次统计,全年共统计8次( ...

  8. poj 2362 Square

    #include <iostream> //参照poj 1011 sticks#include <algorithm>using namespace std;int stick ...

  9. 图论之拓扑排序 poj 2367 Genealogical tree

    题目链接 http://poj.org/problem?id=2367 题意就是给定一系列关系,按这些关系拓扑排序. #include<cstdio> #include<cstrin ...

最新文章

  1. redis集合数据过期_如何从Redis中的集合中自动删除过期的密钥?
  2. 类和对象—对象特性—构造函数和析构函数
  3. mysql两者之间_sql between 语法与查询两者之间数据方法
  4. 【Linux系统编程】I/O多路复用select、poll、epoll的区别使用
  5. 多线程socket 端口扫描程序,实现了,但是速度不行,求指点。
  6. python 卡方检验_【技术】卡方检验及其Python实现
  7. 图书管理系统(一):出版社列表增加、删除和编辑
  8. spring中的@Bean是否一定要与@Configuration一起用
  9. 中文分词与马尔科夫模型之二(隐马尔科夫模型与维特比)
  10. Android开发之设置铃声
  11. CentOS 搭建 高可用 Nginx 集群(keepalived)
  12. 计算机信息专业致谢词,计算机专业毕业论文致谢词
  13. 你真的了解你手机的状态栏吗?
  14. java实现统计pv和uv_shell统计pv与uv、独立ip的方法
  15. Matlab R2017b 自动驾驶工具箱学习笔记(2)_Tutorials_Visual Perception Using Monocular Camera
  16. C语言经典例题:有一对兔子,从出生后第 3 个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,两年内每个月的兔子总数为多少?
  17. 关于「微信小程序」背后的故事
  18. Python 乘法口诀
  19. C语言的3种打桩方法总结
  20. 智能音箱背后的自然语言理解和知识图谱技术

热门文章

  1. 控件注册 - 利用资源文件将dll、ocx打包进exe文件(转)
  2. C++中的继承与虚函数各种概念
  3. Python中map()函数浅析
  4. arachni web mysql数据库_Web安全扫描工具Arachni
  5. python rest 框架_python-更新用户REST框架Django
  6. win10易升_微软Win10版本20H2正式版官方ISO镜像下载大全_windows10_Windows系列_操作系统...
  7. java记录登陆时间_Spring security如何实现记录用户登录时间功能
  8. 栈计算机术语,计算机数据结构词汇中英对照
  9. redux异步action_React躬行记(12)——Redux中间件
  10. centos图形化桌面的文件在哪_CentOS 安装图形桌面