【继续找状态做简单题】HDU 1052 Tian Ji -- The Horse Racing

继续找状态,慢慢恢复:点击打开链接

策略证明如下(声明:PPT为转载):

【继续找状态做简单题】HDU 1052 Tian Ji -- The Horse Racing_第1张图片

【继续找状态做简单题】HDU 1052 Tian Ji -- The Horse Racing_第2张图片

【继续找状态做简单题】HDU 1052 Tian Ji -- The Horse Racing_第3张图片

【继续找状态做简单题】HDU 1052 Tian Ji -- The Horse Racing_第4张图片

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int tian[1001];
int qi[1001];

bool cmp(int a,int b)
{
	return a>b;
}

int main()
{
	int horse;
	while(cin>>horse)
	{
		int tianbest,tianworst,qibest,qiworst;
		int counter=0;
		if(horse==0)
			break;
		for(int i=0;i<horse;i++)
			cin>>tian[i];
		for(int j=0;j<horse;j++)
			cin>>qi[j];
		sort(tian,tian+horse,cmp);
		sort(qi,qi+horse,cmp);
		tianbest=0;
		qibest=0;
		tianworst=horse-1;
		qiworst=horse-1;
		int dui=0;
		while(dui++<horse)
		{
			if(tian[tianbest]>qi[qibest])
			{
				counter+=200;
				tianbest++;
				qibest++;
			}
			
			else if(tian[tianbest]<qi[qibest])
			{
				counter-=200;
				tianworst--;
				qibest++;
			}
			
			else if(tian[tianbest]==qi[qibest])
			{
				if(tian[tianworst]>qi[qiworst])
				{
					counter+=200;
					tianworst--;
					qiworst--;
				}
			    else
			    {
    				if(tian[tianworst]<qi[qibest])
    				{
				    	counter-=200;
				    }
	
   					tianworst--;
   					qibest++;
    			}
			}
			
			
			
			
		}
		cout<<counter<<endl;
				
	}
	return 0;
}


你可能感兴趣的:(【继续找状态做简单题】HDU 1052 Tian Ji -- The Horse Racing)