HDU - 6205 card card card (尺取法)

题意:有n堆牌,ai表示每堆牌的牌数,bi表示每堆牌的penaltyvalue,操作开始前,可以重复进行将第一堆牌挪到最后一堆这一操作。然后,对于挪完后的牌,从第一堆开始,依次取。对于每一堆牌,首先将这堆牌全拿在手中,然后将其全部面朝上翻开,如果手中当前面朝上的牌<该堆牌的penaltyvalue,则游戏停止,该堆牌是可以全部拿走的;否则,将手中面朝上的penaltyvalue数量的牌翻过来使其面朝下,然后继续操作下一堆牌。问操作开始前,最少重复进行多少次挪的操作可以使手中最终拿的牌的数量最多。

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

#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;
}

  

转载于:https://www.cnblogs.com/tyty-Somnuspoppy/p/7519148.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值