当前位置: 代码迷 >> 综合 >> HDU-6205(card card card)
  详细解决方案

HDU-6205(card card card)

热度:107   发布时间:2023-11-23 12:38:45.0

题意: 两个人玩游戏, 有两堆牌, 可以将这两堆牌的前面的牌堆放到后面, 问从第几个开始放能取得最大的牌数, 取牌数的要求是前一对牌数减去后一堆牌数, 如果手牌为0则游戏结束

#include <iostream>using namespace std;const int MAXN = 1e6 + 5;
int a[MAXN * 2], b[MAXN * 2];int main() {int n, p;while (scanf("%d", &n) != EOF) {int cnt = 0;int ans = 0;for (int i = 1; i <= n; ++i) {scanf("%d", &p);a[i] = a[i + n] = p;}for (int i = 1; i <= n; ++i) {scanf("%d", &p);b[i] = b[i + n] = a[i] - p;}// cout << "----" << endl;for (int i = 1; i <= 2 * n; ++i) {cnt += b[i];if (cnt < 0) {ans = i;cnt = 0;}}printf("%d\n", ans);}return 0;
}