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

感觉写的还行AC代码

Posted by CUGB_kdq at 2012-08-18 15:00:43 on Problem 3665
struct kdq
{
    int num,id;
}a[Max];
int main()
{
    int n,m;
    int i,j,k,l;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i].num);
        a[i].id=i;
    }
    int id=-1;
    for(i=0;i<m;i++)
    {
        int mx=0;
        for(j=0;j<n;j++)
        {
            if(mx<a[j].num)
            {
                mx=a[j].num;
                id=j;
            }
        }
        int mod=a[id].num%(n-1);
        int add=a[id].num/(n-1);
        for(j=0;j<n;j++)
        {
            if(j!=id&&mod)
            {
                a[j].num=a[j].num+1+add;
                mod--;
            }
            else if(j!=id)
            {
                a[j].num+=add;
            }
        }
        a[id].num=0;
        printf("%d\n",id+1);
    }
    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