Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个代码

Posted by StepByStepCnmLife at 2015-05-06 23:53:03 on Problem 1089
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator