POJ 1083 Moving Tables

//11168388	c00h00g	1083	Accepted	396K	0MS	G++	765B	2013-01-10 15:27:02
//WA 2次,原因,未考虑from>to的情况
//题意,只需要保存最大重叠次数就行了 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int room[405];
int T,N;

int main(){
    scanf("%d",&T);
    while(T--){
        memset(room,0,sizeof(room));
        scanf("%d",&N);
        int from,to,res=0;
        for(int i=0;i<N;i++){
            scanf("%d%d",&from,&to);
            if(from&1==0)//偶数 
                from--;
            if(to&1==1)//奇数 
                to++;
            if(from>to){
                from=from^to;
                to=from^to;
                from=from^to;
            } 
            for(int j=from;j<=to;j++){
                room[j]++;
                if(res<room[j])
                    res=room[j];
            }
        }
        printf("%d\n",res*10);
    }    
    return 0;
}

你可能感兴趣的:(POJ 1083 Moving Tables)