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 |
贴个代码#include <stdio.h> #include <string.h> #define MAX 1000010 #define max(a,b) (a)>(b)?(a):(b) int board[MAX];//标示区间 int point[MAX];//标示坐标点 int n,maxNum; typedef struct interval{ int a; int b; }interval; interval paintArr[MAX]; void solve() { int i,x,y,j; memset(board+1,0,maxNum*sizeof(int)+1);//board从1开始 memset(point+1,0,maxNum*sizeof(int)+1); for(i=0;i<n;i++) { x=paintArr[i].a; y=paintArr[i].b; if(x==y) { point[x]=1; } else for(j=x;j<y;j++)board[j]=1; } for(i=1;i<=maxNum;i++) { if(point[i]==1||board[i]==1) { if(board[i]==1)//优先考虑存在区间的情况 { printf("%d ",i); while(board[++i]==1); printf("%d\n",i); } else{//point[i]==1的特殊情况 if(board[i]!=1) printf("%d %d\n",i,i); } } } } int main() { int i; scanf("%d",&n); for(i=0,maxNum=0;i<n;i++) { scanf("%d %d",&paintArr[i].a,&paintArr[i].b); maxNum=max(maxNum,paintArr[i].b); } solve(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator