HDU 1199 Color the Ball(线段切割 离散化思想)
来源:互联网 发布:mab软件是什么意思 编辑:程序博客网 时间:2024/06/05 16:01
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1199
这个题目开始一看就知道用线段树加离散化来解,可是好长时间没写线段树了,一时间不知道离散化用线段树怎么搞定
于是就用一个网上称是切割线段的类似模拟方法,感觉这个方法比较容易想,但是写的过程中每一步到底是加一还是减
一都要想好,表示很烦人,开始写的时候其实也挺矛盾,分析下复杂度如果专门挑那些奇怪的测试数据可能会超时,还
是写出来了,果然不出所料wa了几次,但是后来46ms通过可能是数据的问题吧,至于离散化思想我倒是觉得没怎么体
现,反正写出来的代码感觉很恶心了!
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define maxn 2500struct point{ int l; int r;}po[maxn];int pos;int n;int black(int a,int b){ int p=pos; for(int i=0;i<p;i++) { if(a>po[i].r || b<po[i].l) continue; if(a<=po[i].l && b>=po[i].r) po[i].l=0,po[i].r=-1; else if(a>po[i].l && b<po[i].r) po[pos].l=b+1,po[pos].r=po[i].r,po[i].r=a-1,pos++; else if(a<=po[i].l && b<po[i].r) po[i].l=b+1; else if(a>po[i].l && b>=po[i].r) po[i].r=a-1; } return 0;}bool cmp(const point &a,const point &b){ if(a.l==b.l) return a.r < b.r; return a.l < b.l;}int main(){ int i,j,k,a,b; char ch; int ans,left,now,my_pos,re_pos; while(scanf("%d",&n)!=EOF) { ans=0; pos=0; left=0; for(i=0;i<n;i++) { scanf("%d%d",&a,&b); getchar(); scanf("%c",&ch); if(ch=='w') { po[pos].l=a; po[pos].r=b; pos++; } else { black(a,b); } } sort(po,po+pos,cmp); //for(i=0;i<pos;i++) //printf("%d %d \n",po[i].l,po[i].r); if(pos==0) { printf("Oh, my god\n"); continue; } i=0; while(po[i].r==-1) i++; if(i<pos) { now=po[i].r-po[i].l+1; left=po[i].r; my_pos=left; } else ans=0,now=0; for(i;i<pos;i++) { if(po[i].l <= left+1) { if(po[i].r <= left) continue; else now+=po[i].r-left,my_pos=po[i].r,left=po[i].r; } else { if(ans < now) ans=now,re_pos=my_pos; now=po[i].r-po[i].l+1; my_pos=po[i].r,left=po[i].r; } } if(ans < now) ans=now,re_pos=my_pos; if(ans==0) { printf("Oh, my god\n"); continue; } printf("%d %d\n",re_pos-ans+1,re_pos); } return 0;}
- HDU 1199 Color the Ball(线段切割 离散化思想)
- hdu 1199 Color the Ball(离散化线段树)
- hdu 1199 Color the Ball (线段树区间合并,离散化)
- hdu 1199 Color the ball(线段树离散化区间染色)
- ZOJ 2301 / HDU 1199 Color the Ball 离散化+线段树区间连续最大和
- zoj 2301 || hdu 1199 Color the Ball 线段树 离散化
- HDU 1199 Color the Ball (线段树)
- HDU 1199 Color the Ball(离散化入门+非线段树做法)
- ZOJ2301(HDU1199) Color the Ball(线段树离散化)
- HDU 1199.Color the Ball【区间操作(可以用离散化线段树)】【暴力求解】【5月26】
- hdu 1566 Color the ball---线段树
- HDU 1556 Color the ball 线段树
- HDU 1556 Color the ball (线段树)
- HDU 1556 Color the ball 线段树
- hdu 1556 Color the ball(线段树)
- hdu 1556 Color the ball 线段树
- HDU 1556 Color the ball 线段树
- HDU 1556 Color the ball [线段树]
- ora-00600错误
- 一个打通jni,java framework,application三层的练习
- 【公式题】HDU 4651—— Partition
- C Runtime Library、C++ Runtime Library、Windows API 和 C++标准四者之间的关系
- crond无法运行脚本分析
- HDU 1199 Color the Ball(线段切割 离散化思想)
- C++与Python的混合编程-调用有参函数以及C++数据类型与Python数据类型间的转换
- 关于托管代码......
- oracle 的NOLOGGING
- 在 iOS 应用中直接跳转到 AppStore 的方法
- android 防止多次点击
- HTML5新的input类型
- 联机日志文件损坏后的恢复方法
- java的输出类