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 wchrt at 2013-05-09 10:16:29 on Problem 3667
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[500008];
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    a[1]=n;
    int t;
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&t);
        if(t==1)
        {
            scanf("%d",&t);
            int k=n-t+1,i;
            for(i=1;i<=k;i++)
            {
                if(t<=a[i])
                {
                    printf("%d\n",i);
                    a[i+t]=a[i]-t;
                    a[i]=0;
                    break;
                }
            }
            if(i>k){puts("0");}
        }
        else if(t==2)
        {
            int k;
            scanf("%d%d",&k,&t);
            /*for(int j=k;j<=k+t;j++)
            {
                if(a[j]>0)
                {
                    a[k]=max(t,a[j]+j-k);
                    a[j]=0;
                }
            }*/
            a[k]=t;
            if(a[k+t]>0)
            {
                a[k]+=a[k+t];
                a[k+t]=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