标题:关于杭电1052田忌赛马的问题
取消只看楼主
不言葬月
Rank: 1
等 级:新手上路
帖 子:12
专家分:3
注 册:2010-7-22
结帖率:100%
已结贴  问题点数:20 回复次数:4 
关于杭电1052田忌赛马的问题
#include"stdio.h"
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)break;
        int a[2][1024]={0,0},t,p,w,i,j;
        for(i=1;i<=n;i++)scanf("%d",&a[0][i]);
        for(i=1;i<=n;i++)scanf("%d",&a[1][i]);
        for(i=1;i<=n;i++)                            //排序田忌与国王的马的速度
        {
            for(j=1;j<=n-i;j++)
            {
                if(a[0][j]>a[0][j+1])
                {
                    t=a[0][j];
                    a[0][j]=a[0][j+1];
                    a[0][j+1]=t;
                }
                if(a[1][j]>a[1][j+1])
                {
                    t=a[1][j];
                    a[1][j]=a[1][j+1];
                    a[1][j+1]=t;
                }
            }
        }
        w=0;
        for(i=1,j=1;i<=n;i++)                        //用最小的的代价pk掉国王剩下的最差的马,记录胜利次数
        {
            if(a[0][i]>a[1][j])
            {
                a[0][i]=-9999;
                a[1][j]=9999;
                w++;
                j++;
            }
        }
        p=0;
        for(i=1,j=1;i<=n;i++)                //将剩下的可以平局的马平局,记录次数
        {
            for(j=1;j<=n;j++)
            {
                if(a[0][i]==a[1][j])
                {
                    a[0][i]=-9999;
                    a[1][j]=9999;
                    p++;
                    break;
                }
            }
        }
        printf("%d\n",(w-(n-w-p))*200);
    }
}
总是wa,求高手帮我一下啊~~~
搜索更多相关主题的帖子: 田忌 赛马 
2010-08-03 21:19
不言葬月
Rank: 1
等 级:新手上路
帖 子:12
专家分:3
注 册:2010-7-22
得分:0 
怎么沉下去了啊,自己顶一下~~
2010-08-04 08:16
不言葬月
Rank: 1
等 级:新手上路
帖 子:12
专家分:3
注 册:2010-7-22
得分:0 
这个~~~具体的比较方法是怎样的啊~~我已经想不出来啦~~
2010-08-04 16:16
不言葬月
Rank: 1
等 级:新手上路
帖 子:12
专家分:3
注 册:2010-7-22
得分:0 
那平局的要怎么算呢??
2010-08-04 17:05
不言葬月
Rank: 1
等 级:新手上路
帖 子:12
专家分:3
注 册:2010-7-22
得分:0 
终于A了啊,不容易啊~~谢谢各位的帮助哈~~
就是代码有点长~~
#include"stdio.h"
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)break;
        int a[2][1024]={0,0},t,w,i,j,t1=1,g1=1,t2=1,g2=1;
        for(i=1;i<=n;i++)scanf("%d",&a[0][i]);
        for(i=1;i<=n;i++)scanf("%d",&a[1][i]);
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n-i;j++)
            {
                if(a[0][j]<a[0][j+1])
                {
                    t=a[0][j];
                    a[0][j]=a[0][j+1];
                    a[0][j+1]=t;
                }
                if(a[1][j]<a[1][j+1])
                {
                    t=a[1][j];
                    a[1][j]=a[1][j+1];
                    a[1][j+1]=t;
                }
            }
        }
        t2=g2=n;
        w=0;
        for(i=1;i<=n;i++)
        {
            if(a[0][t1]>a[1][g1])
            {
                w++;
                t1++;
                g1++;
                continue;
            }
            if(a[0][t1]==a[1][g1])
            {
                if(a[0][t2]>a[1][g2])
                {
                    w++;
                    t2--;
                    g2--;
                    continue;
                }
                else
                {
                    if(a[0][t2]>a[1][g1])
                    {
                        w++;
                        t2--;
                        g1++;
                        continue;
                    }
                    if(a[0][t2]<a[1][g1])
                    {
                        w--;
                        t2--;
                        g1++;
                        continue;
                    }
                    if(a[0][t2]==a[1][g1])
                    {
                        t2--;
                        g1++;
                        continue;
                    }
                }
            }
            if(a[0][t1]<a[1][g1])
            {
                    if(a[0][t2]>a[1][g1])
                    {
                        w++;
                        t2--;
                        g1++;
                        continue;
                    }
                    if(a[0][t2]<a[1][g1])
                    {
                        w--;
                        t2--;
                        g1++;
                        continue;
                    }
                    if(a[0][t2]==a[1][g1])
                    {
                        t2--;
                        g1++;
                        continue;
                    }
            }
        }
   
        printf("%d\n",w*200);
    }
}
2010-08-04 20:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-314751-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.097726 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved