#include "OJ.h"
#include <stdlib.h>
/*
功能:判断yuanzi 的马是否会赢?yuanzi 的马赢了,返回 YES. 否则返回 NO
输入参数:
unsigned int num: 赛马的数量; (1<= num <=1000)
unsigned int * speed_yz: yuanzi 的马的速度;
unsigned int * speed_op: 对手的马的速度;
输出参数:
无
返回值:
char * 型 的字符串,yuanzi 的马赢了,返回 YES. 否则返回 NO;
*/
char * IsYuanziWin(unsigned int num, unsigned int * speed_yz, unsigned int * speed_op)
{
unsigned int* isExist;
unsigned int i,j,k,temp;
int theCountofWin = 0;
if (num < 1 || num > 1000)
{
return "ERROR";
}
if (speed_op == NULL || speed_yz == NULL)
{
return "ERROR";
}
isExist = (unsigned int* )malloc(num * sizeof(unsigned int));
for (i=0;i<num;i++)
{
isExist[i] = 1;
}
for (i=0;i<num;i++)
{
for (j=i+1;j<num;j++)
{
if (speed_yz[i] > speed_yz[j])
{
temp = speed_yz[i];
speed_yz[i] = speed_yz[j];
speed_yz[j] = temp;
}
if (speed_op[i] < speed_op[j])
{
temp = speed_op[i];
speed_op[i] = speed_op[j];
speed_op[j] = temp;
}
}
}
for (i=0;i<num;i++)
{
for (j=0;j<num;j++)
{
if (isExist[j])
{
if (speed_op[i] < speed_yz[j])
{
isExist[j] = 0;
break;
}
}
}
if (j >= num)
{
for (k=0;k<num;k++)
{
if (isExist[k])
{
isExist[k] = 0;
break;
}
}
theCountofWin -= 1;
}
else
{
theCountofWin += 1;
}
}
free(isExist);
if (theCountofWin > 0)
{
return "YES";
}
else
{
return "NO";
}
}