sgu287:Amusing Qc Machine(DP)

探讨了在特定游戏规则下寻找整数的最坏情况下的最少轮数,通过分析区间缩小策略,揭示了数学与游戏策略的巧妙结合。

题目大意:
      有一个游戏是在一个区间[1,n]中找到一个整数 x。你在每一轮可以说出一个数 y,机器会告诉你 y  x 的大小关系。为了提高游戏难度,机器会延迟 k 轮告诉你这一轮的结果。当机器说结果相等的时候游戏结束。现在给你 n,k ,求出在最坏情况下结束游戏所需的最少轮数。
      1n1015,0k106

分析:
      推荐先去看看 POJ3783 硬蛋那道题,和这道题有异曲同工之妙。
       fi 表示 i 轮游戏能确定的最大区间。
      那么很明显有 fi=fik1+fi1+1 ,再把数组循环一下就好了。

AC code:

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define clr(x, y) memset(x, y, sizeof x)
#define mod(a, b) ((a)<(b)?(a):((a)-(b)))
typedef long long LL;
typedef double DB;
typedef long double LD;
using namespace std;

const int MAXC = 1e6+9;

LL q;
int c;
LL f[MAXC];
LL ans;

void open_init()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
}

void close_file()
{
    #ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
    #endif
}

int main()
{
    open_init();

    cin >> q >> c;
    int cnt = 0;
    while(f[mod(cnt, c+1)] < q)
        f[mod(cnt, c+1)] = f[mod(cnt, c+1)]+f[mod(cnt+c, c+1)]+1, 
        cnt = mod(cnt+1, c+1), ans++;
    cout << ans << endl;

    close_file();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值