题意:有n堆牌,ai表示每堆牌的牌数,bi表示每堆牌的e数量的牌翻过来使其面朝下,然后继续操作下一堆牌。问操作开始前,最少重复进行多少次挪的操作可以使手中最终拿的牌的数量最多。

分析:从第一堆开始,边拿边统计,直到游戏停止,然后从停止的下一张牌开始重新边拿边统计,尺取法思想。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const LL MOD = 998244353;
const double pi = acos(-1.0);
const int MAXN = 1000000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int a[MAXN], b[MAXN];
bool vis[MAXN];
int main(){
    int n;
    while(scanf("%d", &n) == 1){
        memset(vis, false, sizeof vis);
        for(int i = 1; i <= n; ++i){
            scanf("%d", &a[i]);
        }
        for(int i = 1; i <= n; ++i){
            scanf("%d", &b[i]);
        }
        int st = 1, ma = 0, ans = 0;
        while(!vis[n]){
            int sum = 0;
            int cnt = 0;
            int tmp;
            for(int i = 0; i < n; ++i){
                tmp = st + i;
                if(tmp > n) tmp -= n;
                vis[tmp] = true;
                cnt += a[tmp];
                sum += a[tmp];
                if(sum >= b[tmp]){
                    sum -= b[tmp];
                }
                else break;
            }
            if(cnt > ma){
                ma = cnt;
                ans = st - 1;
            }
            st = tmp + 1;
        }
        printf("%d\n", ans);
    }
    return 0;
}

  

相关文章:

  • 2021-09-16
  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
猜你喜欢
  • 2021-07-18
  • 2022-12-23
  • 2021-09-11
  • 2021-09-23
  • 2021-07-21
  • 2022-01-09
相关资源
相似解决方案