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

0ms水过

Posted by ALLACS at 2017-10-11 17:43:57 on Problem 1068
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=20+5;
const int maxn1=2000;
int a[maxn];
int b[maxn];
int s[maxn1];                //圆括号数组
int main()
{
    int t;
    while(scanf("%d",&t)==1&&t)
    {
        int n;
        while(t--)
        {
            memset(s,0,sizeof(s));
            scanf("%d",&n);
            for(int i=0;i<n;i++)
                  {
                      scanf("%d",&a[i]);              //input
                      s[a[i]+i]=2;
                  }
            for(int i=0;i<n;i++)
            {
                int m=a[i]+i;
                int ans=0;
                for(int j=m;j>=0;j--)
                {
                    if(s[j]!=2) ans++;
                    if(!s[j]) {
                                 s[j]=1;
                                 break;
                                }
                }
                b[i]=ans;
            }
            for(int i=0;i<n;i++)
                printf("%d ",b[i]);
            cout<<endl;
        }
    }
    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