sgu287:Amusing Qc Machine(DP)

题目大意:

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

1≤n≤1015,0≤k≤106

分析:

推荐先去看看 POJ3783 硬蛋那道题,和这道题有异曲同工之妙。

设 fi 表示 i 轮游戏能确定的最大区间。

那么很明显有 fi=fi?k?1+fi?1+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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-28 01:56:41

sgu287:Amusing Qc Machine(DP)的相关文章

HDU 1003:Max Sum(DP)

Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 142742    Accepted Submission(s): 33225 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max s

HDU4939:Stupid Tower Defense(DP)

Problem Description FSF is addicted to a stupid tower defense game. The goal of tower defense games is to try to stop enemies from crossing a map by building traps to slow them down and towers which shoot at them as they pass. The map is a line, whic

HDU4901:The Romantic Hero(DP)

Problem Description There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can't refus

POJ1037:A decorative fence(DP)

Description Richard just finished building his new house. Now the only thing the house misses is a cute little wooden fence. He had no idea how to make a wooden fence, so he decided to order one. Somehow he got his hands on the ACME Fence Catalogue 2

codeforces 277.5 div2 F:组合计数类dp

题目大意: 求一个 n*n的 (0,1)矩阵,每行每列都只有两个1 的方案数 且该矩阵的前m行已知 分析: 这个题跟牡丹江区域赛的D题有些类似,都是有关矩阵的行列的覆盖问题 牡丹江D是求概率,这个题是方案数,也比较相似.. 这种题中,因为只要求方案数..我们只要关注几行几列有几个1,而不必要关注具体的位置 题解: 行列都需要处理,因此考虑记录列的状态,然后一行一行的转移 最暴力的方程: dp[i][j][k][t] 表示已经确定了 i 行 有 j列已经有两个1,有k列只有一个1,有t列一个1也没

poj3254:基础状压dp

第二个状压dp 做过的第一个也是放牛问题,两头牛不能相邻 这个题多了一个限制,就是有些位置不能放牛 于是先与处理一下每一行所有不能放牛的状态,处理的过程直接对每一个不能放牛的状态或以下 ac代码: #include <iostream> #include <stdio.h> #include<string.h> #include<algorithm> #include<string> #include<ctype.h> using n

POJ 2955:Brackets(区间DP)

http://poj.org/problem?id=2955 题意:给出一串字符,求括号匹配的数最多是多少. 思路:区间DP. 对于每个枚举的区间边界,如果两边可以配对成括号,那么dp[i][j] = dp[i+1][j-1] + 2,表示由上一个状态加上当前的贡献. 然后和普通的区间合并一样去更新. 1 #include <cstring> 2 #include <cstdio> 3 #include <iostream> 4 #include <string&

UVAlive 10154:Dire Wolf 区间DP

Dire Wolf 题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5073 题意: 有一排的狼,每只狼有一个基础攻击力a[i],和一个加成值b[i](可以给相邻的两只狼加b[i]点攻击力,这只狼死后就不加了),你每杀一只狼需要花费能量值(狼的当前攻击力),你杀了这只狼周围的狼会自动往中间聚集(即不会有空隙),求杀

HDU 2136:Computer(树形DP)

http://acm.split.hdu.edu.cn/showproblem.php?pid=2196 Computer Description A school bought the first computer some time ago(so this computer's id is 1). During the recent years the school bought N-1 new computers. Each new computer was connected to on