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

无语了…………一直WA…………求牛人指点(附代码)

Posted by zxzbos at 2010-11-23 00:51:36 on Problem 1029
思路:
不等时,用一个数组记录每枚硬币的权,初始为0,重的一边加,轻的一边减
相等时,用另一个数组记录是否可能为假硬币,初始为1,出现在平衡的天平上则设为0
最后比较可能为假币的硬币的权的绝对值,取最大的。同时若有2个这样的硬币,则输出0

#include<iostream>

using namespace std;

int main()
{
    int n,k;
    int pi;
    int v1;
    int right[500];
    int left[500];
    char com;
    int q[1001]={0};
    bool fal[1001];
    int key,keyy;
    cin>>n>>k;
    //reset
    for(v1=0;v1!=n+1;++v1)
    {
        fal[v1]=1;
    }
    while(k--)
    {


        //read
        cin>>pi;
        for(v1=0;v1!=pi;++v1)
        {
            cin>>left[v1];
        }
        for(v1=0;v1!=pi;++v1)
        {
            cin>>right[v1];
        }
        cin>>com;

        //compare
        switch(com) {
            case '=':
            {
                for(v1=0;v1!=pi;++v1)
                {
                    fal[right[v1]]=0;
                    fal[left[v1]]=0;
                }
                break;
            }
            case '>':
            {
                for(v1=0;v1!=pi;++v1)
                {
                    --q[right[v1]];
                    ++q[left[v1]];
                }
                break;
            }
            case '<':
            {
                for(v1=0;v1!=pi;++v1)
                {
                    ++q[right[v1]];
                    --q[left[v1]];
                }
                break;
            }
            default:
            ;
        }
        /*;
        for(v1=1;v1!=n+1;++v1)
        {
            cout<<q[v1]<<" ";
        }
        cout<<endl;
        for(v1=1;v1!=n+1;++v1)
        {
            cout<<fal[v1]<<" ";
        }
        cout<<endl;
        ;*/
    }
    //decide
    key=0;
    keyy=0;
    for(v1=1;v1!=n+1;++v1)
    {
        if(fal[v1])
        {
            if(key==0)
            {
                key=v1;
                keyy=1;
                continue;
            }
            if(q[v1])
            {
                if(abs(q[key])<abs(q[v1]))
                {
                    key=v1;
                    keyy=1;
                }
                else if(abs(q[key])==abs(q[v1]))
                     {
                         keyy=0;
                     }
            }

        }
    }

    //print
    if(keyy)
    {
        cout<<key<<endl;
    }
    else
    {
        cout<<0<<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