自己独立写出来的 有点意思 就赛出来了
#include<iostream>
using namespace std;
/*
题:田忌和齐威王赛马,齐威王每次用速度最快的马,求田忌怎么选马
贪心法
比他们的速度
*/
int main()
{
int a[100] = { 36,35,34,30,29,20,15,12,9,8,6 };//齐威王马速
int b[100] = { 33,32,25,23,18,17,16,14,10,7,5 };//田忌马速
int n = 11,m=11;
int j = 0;
int count = 0;
for (int i = 0; i < m; i++)
{
int t1 = a[i];
int t2;
cout << "齐威王选" << t1 << " ";
if (t1 > b[j])
{
cout << "田忌选" << b[n - 1] << " ";
t2 = b[n - 1];
n--;
}
else
{
cout << "田忌选" << b[j] << " ";
t2 = b[j];
j++;
}
if (t1 > t2) cout << "田忌败!" << endl;
else
{
cout << "田忌胜!" << endl;
count++;
}
}
cout << "田忌胜" << count << "场" << endl;
cout << "田忌败" << 11-count << "场" << endl;
return 0;
}