2018湖南省第14届大学生计算机程序设计竞赛 C: 时间旅行

Description

假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中。

当 Bobo 位于时间轴上 t 点,同时时间机器有 c 单位燃料时,他可以选择一个满足 xhhc⌈xh⌉⋅h≤c 的非负整数 x, 那么时间机器会在 [0, x]中随机整数 y,使 Bobo 回到 (t − y) 点,同时消耗 y 单位燃料。 (其中 ⌈ ⋅ ⌉ 表示上取整)

因为时间机器的随机性,对于给出的参数 h 和时间机器剩余燃料 c,Bobo 想知道能够保证回到区间 (0, h] 中的 t0 的最大值。

  • 1 ≤ h ≤ 109
  • 0 ≤ c ≤ 109
  • 数据组数不超过 105.

Input

输入文件包含多组数据,请处理到文件结束。

每组数据包含 2 个整数 h 和 c.

Output

对于每组数据输出 1 个整数表示 t0 的最大值。

Sample Input

100 99
100 100
100 149

Sample Output

100
101
150

解题:这题莽一发就过了,你推一下会发现x的最大值是c/h的向下取整乘以h,然后依照题意就选择这个值运算,到最后小于h的时候就是比h小的值+1。最后结果还是c+1。
当然你要考虑一开始h和c的大小,如果c比较小的时候,就是答案就是h的值。
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <list>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
const double pi=acos(-1.0);
const int MOD=10056;
const int maxn=2016;
int h,c;

int main()
{
    while(scanf("%d %d",&h,&c)!=EOF)
    {
        if(h>c)
            printf("%d\n",h);
        else
            printf("%d\n",c+1);
    }
    return 0;
}

/**********************************************************************
    Problem: 1360
    User: HNCPCteam001
    Language: C++
    Result: AC
    Time:108 ms
    Memory:2024 kb
**********************************************************************/

猜你喜欢

转载自www.cnblogs.com/jkzr/p/9589277.html