2017招 银 编程题
来源:互联网 发布:外盘期货数据接口api 编辑:程序博客网 时间:2024/05/29 21:33
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
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;
}
}
#include <cmath>
#include <algorithm>
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;
}
}
阅读全文
0 0
- 2017招 银 编程题
- 2017秋招编程题
- 2017秋招编程题小记
- 2017 百度校招 编程题
- 携程2017 校招编程题
- 网易2017秋招编程题
- 网易2017秋招编程题
- 网易2017秋招编程题
- 网易2017秋招编程题集合
- 2017网易秋招编程题7
- 网易2017秋招编程题8
- 网易2017秋招编程题2
- 网易2017秋招编程题6
- 网易2017秋招编程题1
- 2017中兴通讯校招编程题
- 网易2017秋招编程题集合
- 滴滴出行2017秋招编程题
- 网易2017秋招编程题
- 【python】图形用户界面入门:EasyGui学习超详细版
- 王者荣耀:从程序员的角度解密王者荣耀,专业术语把院长看懵了
- 【牛客 题库】 virtual 函数 求输出结果
- MFC一一添加WM_USER自定义消息
- 牛客网-剑指offer-14-打印一个链表的倒数第k个节点
- 2017招 银 编程题
- ajax同步异步和使用a链接
- tcp
- MyBatis Generator系列(一)----MyBatis Generator简介
- MOOC清华《面向对象程序设计》第7章:统计考试及格率v5.2(用文件输入及格线)
- oracle 监听原理、配置、异常处理
- caffe源码学习记录
- Java Web第二章 例2-2,3,4
- [算法分析与设计] leetcode 每周一题: 62. Unique Paths