HOJ_1052:Tian Ji -- The Horse Racing 贪心

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052

代码:

//hoj_1052
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1010;

int main()
{
    int n,i;
	int t[N],w[N];
    while(scanf("%d",&n)&&n)
    {
        for (i=0;i<n;i++)
			cin>>t[i];
		for (i=0;i<n;i++)
			cin>>w[i];
        sort(t,t+n);
        sort(w,w+n);
        int i1=0,i2=n-1;
        int j1=0,j2=n-1;
        int num=0;
        while(i1<=i2&&j1<=j2)
        {
            if(t[i1]>w[j1])
            {
                num++;
                i1++;j1++;
            }
            else if(t[i1]<w[j1])
            {
                num--;
                i1++;j2--;
            }
            else
            {
                if(t[i2]>w[j2])
                {
                    num++;
                    i2--;j2--;
                }
                else if(t[i2]<w[j2])
                {
                    num--;
                    i1++;j2--;
                }
                else if(t[i2]==w[j2])
                {
                    if(t[i1]<w[j2])
                    {
                        num--;
                        i1++;j2--;
                    }
                    else if(t[i1]==w[j2])
                    {
                        break;
                    }
                }
            }
        }
        cout<<num*200<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42173572/article/details/82156054