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

g++wa, c++ac, 不解。。。我自己调试什么都是用g++

Posted by sicojuy at 2011-04-05 18:44:45 on Problem 1015
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

#define N 800
#define inf 10000000

struct node
{
    bool status[200];
    int plus;
    int sump;
    int sumd;
};

struct node dp[20][N];

int main()
{
    int i, j, k, r, n, m, round = 0;
    int defence[200], prosecution[200], plus[200], sub[200];
    int index, size, dsize;
    struct node init;
    memset(&init, 0, sizeof(init));
    while(scanf("%d%d", &n, &m), n != 0)
    {
        size = m * 20;
        dsize = size + size;
        for(i = 0; i < dsize; ++i)
        {
            dp[0][i].plus = inf;
        }
        for(i = 0; i < n; ++i)
        {
            scanf("%d%d", &prosecution[i], &defence[i]);
            sub[i] = prosecution[i] - defence[i];
            plus[i] = prosecution[i] + defence[i];
            index = sub[i] + size;
            if(dp[0][index].plus == inf || plus[i] > dp[0][index].plus)
            {
                dp[0][index] = init;
                dp[0][index].plus = plus[i];
                dp[0][index].status[i] = true;
                dp[0][index].sump = prosecution[i];
                dp[0][index].sumd = defence[i];
            }
        }
        for(i = 1; i < m; ++i)
        {
            r = i - 1;
            for(j = 0; j < dsize; ++j)
            {
                dp[i][j].plus = inf;
            }
            for(j = 0; j < dsize; ++j)
            {
                if(dp[r][j].plus != inf)
                {
                    for(k = 0; k < n; ++k)
                    {
                        if(dp[r][j].status[k] == true)
                            continue;
                        index = j + sub[k];
                        if(dp[i][index].plus == inf || dp[r][j].plus + plus[k] > dp[i][index].plus)
                        {
                            dp[i][index] = dp[r][j];
                            dp[i][index].status[k] = true;
                            dp[i][index].sump += prosecution[k];
                            dp[i][index].sumd += defence[k];
                            dp[i][index].plus = dp[r][j].plus + plus[k];
                        }
                    }
                }
            }
        }

        for(r = m - 1, i = j = size; i < dsize ; ++i, --j)
        {
            if(dp[r][i].plus != inf)
            {
                index = i;
                break;
            }
            if(dp[r][j].plus != inf)
            {
                index = j;
                break;
            }
        }
        if(dp[r][i].plus != inf && dp[r][j].plus != inf)
        {
            if(dp[r][i].plus > dp[r][j].plus)
                index = i;
            else
                index = j;
        }
        printf("Jury #%d\n", ++round);
        printf("Best jury has value %d for prosecution and value %d for defence:\n", dp[r][index].sump, dp[r][index].sumd);
        for(i = 0; i < n; ++i)
            if(dp[r][index].status[i] == true)
                printf(" %d", i + 1);
        printf("\n\n");
    }
    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