| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
首先庆祝用漂浮法模拟过了,还很快,188MS~~~~~然后悲剧用离散化+线段树挂了,求解~下面是过的代码,用的漂浮法,从USACO上那个矩形切割得到的灵感
#include "stdio.h"
#include "string.h"
int x[10001];
int y[10001];
int n;
int ans[10001];
void cover(int l,int r,int k,int c){
while(k<n&&(r<x[k]||l>y[k])){
k++;
}
if(k>=n){
ans[c]+=r-l+1;
return;
}
if(l<x[k]){
cover(l,x[k]-1,k+1,c);
l=x[k];
}
if(r>y[k]){
cover(y[k]+1,r,k+1,c);
r=y[k];
}
}
int main(){
int t,i,j;
int sum;
scanf("%d",&t);
while(t--){
sum=0;
memset(ans,0,sizeof(ans));
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d%d",&x[i],&y[i]);
}
for(i=n-1;i>=0;i--){
cover(x[i],y[i],i+1,i);
}
for(i=0;i<n;i++){
if(ans[i]>0)
sum++;
}
printf("%d\n",sum);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator