C. Greedy Arkady
kk people want to split nn candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from 11 to kk, and Arkady is the first of them. To split the candies, Arkady will choose an integer xx and then give the first xx candies to himself, the next xx candies to the second person, the next xx candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by xx) will be thrown away.
Arkady can't choose xx greater than MM as it is considered greedy. Also, he can't choose such a small xxthat some person will receive candies more than DD times, as it is considered a slow splitting.
Please find what is the maximum number of candies Arkady can receive by choosing some valid xx.
The only line contains four integers nn, kk, MM and DD (2≤n≤10182≤n≤1018, 2≤k≤n2≤k≤n, 1≤M≤n1≤M≤n, 1≤D≤min(n,1000)1≤D≤min(n,1000), M⋅D⋅k≥nM⋅D⋅k≥n) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.
Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid xx.
20 4 5 2
8
30 9 4 1
4
In the first example Arkady should choose x=4x=4. He will give 44 candies to himself, 44 candies to the second person, 44 candies to the third person, then 44 candies to the fourth person and then again 44candies to himself. No person is given candies more than 22 times, and Arkady receives 88 candies in total.
Note that if Arkady chooses x=5x=5, he will receive only 55 candies, and if he chooses x=3x=3, he will receive only 3+3=63+3=6 candies as well as the second person, the third and the fourth persons will receive 33candies, and 22 candies will be thrown away. He can't choose x=1x=1 nor x=2x=2 because in these cases he will receive candies more than 22 times.
In the second example Arkady has to choose x=4x=4, because any smaller value leads to him receiving candies more than 11 time.
数学题,d比较小,枚举d
贪心思考,最好应该是第一个人取i次,其他人取i-1次
x*i+x*(i-1)*(k-1)<=n
若x>m 取x=m 然后重新判断是否可以到 i 组
//#include <bits/stdc++.h>
#include<iostream>
#include<stack>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (ll i = (a); i <= (b); i++)
#define FFor(i, a, b) for (int i = a; i >= (b); i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int N = ;
const int M=;
// name*******************************
ll n,k,m,d;
ll t;
ll ans=;
// function****************************** //***************************************
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
cin>>n>>k>>m>>d;
For(i,,d)
{
ll x=n/((i-)*k+);
if(!x)break;
if(x>m)x=m;
if(n/(k*x)+((n%(k*x)>=x)?:)!=i)continue;
ans=max(ans,x*i);
}
cout<<ans;
return ;
}
C. Greedy Arkady的更多相关文章
- 「日常训练」Greedy Arkady (CFR476D2C)
不用问为啥完全一致,那个CSDN的也是我的,我搬过来了而已. 题意(Codeforces 965C) $k$人分$n$个糖果,每个糖果至多属于1个人.A某人是第一个拿糖果的.(这点很重要!!) 他$x ...
- cf965c Greedy Arkady
呸,大傻逼题,我更傻逼ref #include <iostream> using namespace std; typedef long long ll; ll n, k, m, d, a ...
- 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] C】Greedy Arkady
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举那个人收到了几次糖i. 最好的情况显然是其他人都只收到i-1次糖. 然后这个人刚好多收了一次糖 也即 (i-1)kx + x & ...
- Codeforces Round #476 (Div. 2) [Thanks, Telegram!] ABCDE
修仙场,没脑子,C边界判错一直在写mdzz..D根本没怎么想. 第二天起来想了想D这不是水题吗立马A了.看了看E一开始想分配问题后来发觉想岔了,只需要每次都把树最后分配的点移到最前面就好了. A. P ...
- USACO . Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
- hdu4976 A simple greedy problem. (贪心+DP)
http://acm.hdu.edu.cn/showproblem.php?pid=4976 2014 Multi-University Training Contest 10 1006 A simp ...
- ACM Greedy Mouse
Greedy Mouse 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 A fat mouse prepared M pounds of cat food,read ...
- hdu 1053 (huffman coding, greedy algorithm, std::partition, std::priority_queue ) 分类: hdoj 2015-06-18 19:11 22人阅读 评论(0) 收藏
huffman coding, greedy algorithm. std::priority_queue, std::partition, when i use the three commente ...
- Greedy
在现实世界中,有这样一类问题:它有n个输入,而它的解就由这n个输入的某个子集组成,不过这个子集必须满足某些事先给定的条件.把那些必须满足的条件称为约束条件:而把满足约束条件的子集称为该问题的可行解.问 ...
随机推荐
- 阿里云服务器(ECS)从购买到配置NodeJS环境
本人入门级前端,对服务器不熟悉,这是自己摸索的过程,可能会有错误! 1.购买 阿里云服务器有个活动是新用户前六个月可以免费试用,但是每天早上发放一定的名额,但为了方便,我买了18RMB的捆绑套餐,也是 ...
- js-ES6学习笔记-Class
1.ES6提供了更接近传统语言的写法,引入了Class(类)这个概念,作为对象的模板.通过class关键字,可以定义类. 2. //定义类 class Point { constructor(x, y ...
- Android JNI的使用方法
1.JNI是什么 JNI是Java Native Interface的缩写,它提供若干的API实现Java与其他语言之间的通信.而Android Framework由基于Java语言的的Java层与基 ...
- 2018-10-23 23:29:54 clanguage
2018-10-23 23:29:54 clanguage 在 32 位环境以及 Win64 环境下的运行结果为: short=2, int=4, long=4, char=1 在 64 位 Li ...
- iOS 开发多线程 —— GCD(1)
本文是根据文顶顶老师的博客学习总结而来,如有不妥之处,还望指出.http://www.cnblogs.com/wendingding/p/3807716.html 概览: /* 纯c语言,提供了非常多 ...
- UWP开发细节记录:DirectX::XMMATRIX 的坑
这两天写的代码概率性的崩溃在 XMMatrixMultiply() 函数,XMMatrixMultiply() 本身是 inline 函数可以看到崩溃处的代码: vX = _mm_mul_ps(vX, ...
- 前端构建工具Gulp使用总结
1.安装准备 1.1 Node.js安装 在安装Gulp之前首先的安装Node.js, 安装教程详见Node.js 安装配置 1.2 npm安装 在安装node的时候会自动安装npm模块管理器,详见n ...
- 在Docker Swarm上部署Apache Storm:第1部分
[编者按]本文来自 Baqend Tech Blog,描述了如何在 Docker Swarm,而不是在虚拟机上部署和调配Apache Storm集群.文章系国内 ITOM 管理平台 OneAPM 编译 ...
- API接口安全设计(转)
接口的安全性主要围绕Token.Timestamp和Sign三个机制展开设计,保证接口的数据不会被篡改和重复调用,下面具体来看: Token授权机制:用户使用用户名密码登录后服务器给客户端返回一个To ...
- BBR,附CentOS 6/7配置过程
最近这段时间BBR都比较火,前面有说如何在CAC的Debian-8-64bit安装BBR正确打开方式,现在说下,CentOS 6/7配置过程. 推荐理由:没配置BBR前,用SS看U2B的速度206K/ ...