2017招 银 编程题

#include
#include
#include
#include
using namespace std;


#define M 5010


int main()
{
int n;
while (cin >> n)
{
int a[M] = { 0 }, sum = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
sum += a[i];
}
sum /= 2;
int ag = 0, now = 0, bg = 0;
int round = 1;
while (ag <= sum&&bg <= sum&&now<=n)  //谁先超过一半 就赢
{
int s = 0;
if (a[now] >= a[now+1] + a[now+2])  //避免后面的打牌被对手拿到
{
s = a[now];
now += 1;
}
else   //减少与对手的差距
{
s = a[now] + a[now + 1];
now += 2;
}
if (round == 1) //谁的回合
{
ag += s;
round = 2;
}
else
{
bg += s;
round = 1;
}
}
if (ag>sum) cout << "true" << endl;
else cout << "false" << endl;
}
}








你可能感兴趣的:(应聘笔试题)