GDUT_排位赛题解报告_第3场_B.Loan Repayment
题目:
Farmer John owes Bessie N gallons of milk (1≤N≤1012). He has to give her the milk within K days. However, he doesn’t want to give the milk away too quickly. On the other hand, he has to make forward progress on the loan, so he must give Bessie at least M gallons of milk each day (1≤M≤1012).
Here is how Farmer John decides to pay back Bessie. He first picks a positive integer X. He then repeats the following procedure every day:
Assuming that Farmer John has already given Bessie G gallons, compute N−GX rounded down. Call this number Y. If Y is less than M, set Y to M. Give Bessie Y gallons of milk. Determine the largest X such that if Farmer John follows the above procedure, Farmer John gives Bessie at least N gallons of milk after K days (1≤K≤1012).
Input
The only line of input contains three space-separated positive integers N, K, and M satisfying K⋅M<N.
Output
Output the largest positive integer X such that Farmer John will give Bessie at least N gallons using the above procedure.
Example
inputCopy
10 3 3
outputCopy
2
Note
For the first test case, when X=2 Farmer John gives Bessie 5 gallons on the first day and M=3 gallons on each of the next two days.
Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a “long long” in C/C++).
这个题目看起来就是模拟,但是很多人可能难以处理的点就是其中一个问题,模拟每天给同样数目的牛奶的时候,如何删去这些重复的步骤。
我们看一下这个东西:
bool check(LL num)
{/*LL G=0;LL day=0;while(1){if((n-G)%m==0&&(n-G)/m+day<=k)return true;else if((n-G)%m!=0&&(n-G)/m+day+1<=k)return true;if((n-G)/num<=m)return false;G+=(n-G)/num;day++;}*/LL kk=k,G=0;while(G<n&&kk>0){LL y=(n-G)/num;if(y<m){LL o=(n-G+m-1)/m;return o<=kk;}LL ch=n-num*y;LL d=(ch-G)/y+1;d=min(d,kk);G+=y*d;kk-=d;}return G>=n;
}
我们看看如何跳过了那段时间:注意看这一步:
LL ch=n-num*y;LL d=(ch-G)/y+1;d=min(d,kk);G+=y*d;kk-=d
这就是利用整数除法把所有相同的牛奶给省出去了,这样就是省下来一大堆时间,然后就能过了:
完整代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <queue>
#include <stack>
#include <map>
//鬼畜头文件
using namespace std;
const int INF = 0x3f3f3f3f;
//1.06e9大小
const int mod = 1e9+7;
typedef unsigned long long ULL;
typedef long long LL;
//鬼畜define// typedef struct note{};
LL n,k,m;
bool check(LL num)
{/*LL G=0;LL day=0;while(1){if((n-G)%m==0&&(n-G)/m+day<=k)return true;else if((n-G)%m!=0&&(n-G)/m+day+1<=k)return true;if((n-G)/num<=m)return false;G+=(n-G)/num;day++;}*/LL kk=k,G=0;while(G<n&&kk>0){LL y=(n-G)/num;if(y<m){LL o=(n-G+m-1)/m;return o<=kk;}LL ch=n-num*y;LL d=(ch-G)/y+1;d=min(d,kk);G+=y*d;kk-=d;}return G>=n;
}
int main()
{scanf("%lld %lld %lld",&n,&k,&m);LL left=1;LL right=min(n/m,k);while(left+1<right){LL mid=(left+right)/2;if(check(mid)){left=mid;}else right=mid;}printf("%lld\n",left);return 0;
}
GDUT_排位赛题解报告_第3场_B.Loan Repayment相关推荐
- GDUT_排位赛题解报告_第5场_A. 唯一排列
题目 ChenJr给你一个长度为n的排列p,你可以交换其中任意相邻的两个数.现在你需要用最小的交换次数使得这个排列变成升序的序列.现在ChenJr想知道,对于这个排列p,是否存在唯一的交换方式,使得这 ...
- GDUT_排位赛题解报告_第2场_Fence Planning
题目: A. Fence Planning time limit per test1 second memory limit per test256 megabytes inputstandard i ...
- GDUT_排位赛题解报告_第5场_C. 积木
题目: ChenJr已经两个月没有出门了,因此他已经无聊到开始用积木来玩搭房子游戏了. ChenJr首先规定,对于搭建的每一栋房子,他只能选取长度为n的积木作为地基,之后他根据下述的规则进行搭建. 如 ...
- 题解报告(CDUT暑期集训——第三场)
题解报告(CDUT暑期集训--第三场) A - Problem A. Ascending Rating HDU - 6319 思路:单调队列板子题?(但是弱的一批的我还是不会用(有空补上 用的滑动窗口 ...
- 题解报告(CDUT暑期集训——第二场)
题解报告(CDUT暑期集训--第二场) D - Game HDU - 6312 思路:水题 Alice一直是必胜态 AC代码 #include<stdio.h> #include<i ...
- 题解报告(CDUT暑期集训——第四场)
题解报告(CDUT暑期集训--第四场) Problem D. Nothing is Impossible HDU - 6335 思路:水题 排个序循环判断就出来了 AC代码 #include<s ...
- 题解报告(CDUT暑期集训——第一场)
题解报告(CDUT暑期集训--第一场) A - Maximum Multiple HDU - 6298 思路:先按照题意打表 发现规律 就出来了(最开始没开long long贡献了3发 然后又忘了换行 ...
- 题解报告(CDUT暑期集训——第六场)
题解报告(CDUT暑期集训--第六场) A - oval-and-rectangle HDU - 6362 思路:水题 积分一化就出来了 AC代码 #include<stdio.h> #i ...
- 题解报告(CDUT暑期集训——第五场)
题解报告(CDUT暑期集训--第五场) B - Beautiful Now HDU - 6351 思路:直接暴力全排列就行了 最多\(10!\)次 题目限制2500ms 全排列大概是2000多ms(最 ...
最新文章
- 在一台机器上搭建多个redis实例
- MyEclipse极速优化
- linux系统下载经验,linux系统的学习经验首篇
- 11月25日struts培训日记
- Java网络编程从入门到精通(21):HTTP消息的格式
- JQuery中this指向
- WP8开发札记(一)WP8应用生命周期管理
- 【方案分享】2022线上云年会云会议玩法全案策划.pptx(附下载链接)
- java异常机制_全面理解java异常机制
- “渠道之王”2.0 百丽携手乐淘的背后
- VB--Adodc控件
- 排序(2)二分排序、快速排序、归并排序
- cad放大_dwg文件怎么打开?CAD看图,360°精确识别CAD图块,细节见真章
- 永远跳票的 永远的毁灭公爵
- ARCore:从Android Studio开始
- 用matlab做仿真实验难不难,SIMULINK仿真实验心得体会
- meson test 的 --test-args 参数
- 指付通盗刷信用卡维权连载--9月5日给上海银监局的一封信
- jvm full gc到底是啥意思
- 滴滴出行小程序体积优化实践