zoj 2301 Color the Ball
2012-09-21 21:19
369 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2301
题目大意:求最长连续白色球。
题目思路:矩形切割,最长排序即可。
题目大意:求最长连续白色球。
题目思路:矩形切割,最长排序即可。
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<string> #include<queue> #include<algorithm> #include<vector> #include<stack> #include<list> #include<iostream> #include<map> #include<math.h> using namespace std; #define inf 0x3f3f3f3f #define uint unsigned __int64 #define M 5000 struct node { int p1,p2; char tp[3]; bool operator<(const node a)const { return p1<a.p1; } }a[M],now; int total; int judge(node a,node b) { if(a.p2<b.p1||a.p1>b.p2) return 0; return 1; } void cut(node tmp) { int k1,k2; k1=max(tmp.p1,now.p1); k2=min(tmp.p2,now.p2); if(tmp.p1<k1) { a[++total]=tmp; a[total].p2=k1-1; } if(tmp.p2>k2) { a[++total]=tmp; a[total].p1=k2+1; } } int main() { int n,i,j; while(scanf("%d",&n)!=EOF) { total=0; for(i=0;i<n;i++) { scanf("%d%d%s",&now.p1,&now.p2,now.tp); if(now.p1>now.p2) swap(now.p1,now.p2); for(j=total;j>=1;j--) { if(judge(a[j],now)) { cut(a[j]); a[j]=a[total--]; } } a[++total]=now; } sort(a+1,a+total+1); int ans=0,cnt=0; int le,ri; if(n&&a[1].tp[0]=='w') a[cnt++]=a[1]; for(i=2;i<=total;i++) { if(a[i].tp[0]=='b') continue; if(a[i-1].tp[0]=='w'&&a[i-1].p2+1==a[i].p1) a[cnt-1].p2=a[i].p2; else a[cnt++]=a[i]; } for(i=0;i<cnt;i++) { if(a[i].p2-a[i].p1+1>ans) { ans=a[i].p2-a[i].p1+1; le=a[i].p1; ri=a[i].p2; } } if(ans==0) { puts("Oh, my god"); continue; } printf("%d %d\n",le,ri); } }
相关文章推荐
- ZOJ 2301 Color the Ball 线段树 区间染色
- zoj 2301 || hdu 1199 Color the Ball
- zoj 2301 || hdu 1199 Color the Ball 线段树 离散化
- zoj 2301 Color the Ball(区间染色,线段树+离散化)
- [尚未搞定] zoj 2301 Color the Ball
- ZOJ 2301 Color the Ball 线段树(区间更新+离散化)
- HDU 1556 Color the ball
- HDU1556:Color the ball(线段树区间更新)
- hdoj-1556-Color the ball
- HDU 1556 Color the ball
- Color the ball
- hdu 1556:Color the ball(线段树,区间更新,经典题)
- HDU 1556 Color the ball
- Color the ball
- HDU 1556 Color the ball (一维树状数组,区间更新,单点查询)
- hdu1556 Color the ball
- hdu 1556 Color the ball
- color the ball -- hdu -- 树状数组
- HDU - 1556——Color the ball
- hdu 1556 Color the ball (树状数组解决区间覆盖+单点查询)