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,一个就WA了呢,求指教!!

Posted by Billows1 at 2012-05-05 20:48:30 on Problem 3665
首先写的WA了:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int n, t, maxx, pos;
    int r[1006]={0};
    int i, j, x, y, s;

    while (scanf("%d%d",&n,&t) != EOF)
    {
        for (i=0; i<n; i++)
        scanf("%d",&r[i]);
        s = 0;
        pos = -1;
        while (t--)
        {

            x = s % (n-1);
            y = s / (n-1);
            i = 0;
            while (x)
            {
                if (i != pos)
                {
                    r[i] += 1;
                    x--;
                }
                i++;
            }
            maxx = -1;
            for (i=0; i<n ;i++)
            {
                r[i] += y;
                if(r[i] > maxx)
                {
                    maxx = r[i];
                    pos = i;
                }
            }
            printf("%d\n",pos+1);
            s = r[pos];
            r[pos] = 0;
        }
    }
    return 0;
}

又写了一个,AC了:

#include <stdio.h>

int main()
{
    int r[1006]={0};
    int n, t, maxx, pos;
    int x, y, i, j;

    while (scanf("%d%d",&n ,&t) != EOF)
    {
        for (i = 0; i < n; i++)
        scanf("%d", &r[i]);
        while (t--)
        {
            maxx = -1;
            for (i = 0; i < n ; i++)
            if (r[i] > maxx)
            {
                maxx = r[i];
                pos = i;
            }
            printf("%d\n",pos+1);
            x = r[pos] % (n-1);
            y = r[pos] / (n-1);

            i = 0;
            while (x)
            {
                if(i != pos)
                {
                    r[i] += 1;
                    x--;
                }
                i++;
            }
            for (i = 0 ; i < n ; i++)
            r[i] += y;
            r[pos] = 0;
        }
    }
    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