Codeforces Round #476 (Div. 2) C - Greedy Arkady
Examples 1:
input:
20 4 5 2
output:
8Examples 2:
input:
30 9 4 1
output:
4
题意:
n,k,m,d分别表示n颗糖,k个人,一次分给一个人的糖果数不能大于m,
但是不能有一个人收到糖果的次数大于d,问你一次给每人发几颗糖,才能
让Arkady得到的糖最多
菜鸡分析:
第一我是想直接二分糖的数目,可是看了样例一的note,发现不能直
接二分糖的数目,应该在n颗糖可以分几轮的基础上进行二分,找出Arkady
最多可以得到的糖,也就是说应该先枚举1->d分糖的轮数,每一种情况在
进行二分找最大,最后再从所有的可能性中选取最大的颗数
个人代码:
#define debug
#include<stdio.h>
#include<math.h>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<functional>
#include<iomanip>
#include<map>
#include<set>
#define pb push_back
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>PLL;
typedef pair<int,ll>Pil;
const ll INF = 0x3f3f3f3f;
const double inf=1e8+100;
const double eps=1e-8;
const int maxn =5e5;
const int N = 510;
const ll mod=1e9+7;
const ll MOD=1e9;
//------
//define
ll n,k,m,d,ans=-1,tmp=0;
//geti
ll geti(ll i) {ll eh=n/i;ll circle=(eh-1)/k+1;return circle;
}
//solve
void solve() {while(cin>>n>>k>>m>>d) {ans=-1;for(int i=1; i<=d; i++) {ll l=1,r=m;tmp=0;while(l<=r) {ll m=l+(r-l)/2;ll tt=geti(m);if(tt==i) {tmp=m*i;l=m+1;} else if(tt>i) {l=m+1;} else {r=m-1;}}ans=max(ans,tmp);}cout<<ans<<endl;}
}
//main
int main() {ios_base::sync_with_stdio(false);
#ifdef debugfreopen("in.txt", "r", stdin);
// freopen("out.txt","w",stdout);
#endifcin.tie(0);cout.tie(0);solve();/*#ifdef debugfclose(stdin);fclose(stdout);system("out.txt");#endif*/return 0;
}
转载于:https://www.cnblogs.com/visualVK/p/8992587.html
Codeforces Round #476 (Div. 2) C - Greedy Arkady相关推荐
- Codeforces Round #476 (Div. 2) C. Greedy Arkady
点击打开题目链接 知道了当第一个人比那 k-1 个人多分一次x就是最优策略 和 对分糖果的次数进行枚举就差不多了 当分i次的时候, 有 (i-1)*x(k-1)+x+i<=n; x=n/((i- ...
- Codeforces Round #476 (Div. 2)
LINK A.B 水题 C. Greedy Arkady 题意 现有n个糖果,分给k个人,编号为1~k,你可以选择X,按顺序给个人x个,直至分完或者不足X个的舍弃,X<=M ,每个人得到糖果的次 ...
- Codeforces Round #476 (Div. 2) B. Battleship
用暴力就可以过,不过晚上做的时候被题面和自己的英语水平唬着了,没做.也是签到题吧,不过自己写的比较乱 点击打开题目链接 #include <iostream> #include <c ...
- Codeforces Round #476 (Div. 2) A. Paper Airplanes
点击打开题目链接 签到题 #include <iostream> using namespace std; int main() {int k,n,s,p;cin>>k> ...
- Codeforces Round #653 (Div. 3)(A, B, C, D, E1详解)
Codeforces Round #653 (Div. 3) Required Remainder Thinking(binary search) 既然是找最大值问题,我又懒得去推式子,于是我直接就上 ...
- Codeforces Round #776 (Div. 3) A B C D E
Codeforces Round #776 (Div. 3) A B C D E A. Deletions of Two Adjacent Letters Tip: Implementation.St ...
- Codeforces Round #506 (Div. 3)
Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...
- Codeforces Round #563 (Div. 2)/CF1174
Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...
最新文章
- VS Code - Debugger for Chrome调试JavaScript的两种方式
- 完美解决Linux服务器tomcat开机自启动问题
- 通信专业学python有用吗-通信人不会这项技能,5G时代很难拿到高薪
- 史上最详细的SSM框架整合(Spring、SpringMVC、Mybatis)
- test 7 3-22 2021省选模拟赛seven
- KAFKA 集成 SpringBoot2 消息发送和消费消息(基础篇)
- 路由器POS接入方式
- ImportError: No module named six
- java多线程问题,线程交替执行
- Service绑定模式
- netperf网卡测速ubuntu linux 环境下测硬件网卡速度
- 吉林大学计算机学院换届,CCF吉林大学学生分会举行换届选举会议-中国计算机学会...
- MSDEV.EXE-应用程序错误解决办法(转)
- 小谈 《日内交易策略--谷物期货交易实战指南》中提到的策略
- ORB_SLAM2源码阅读(一)概要
- java开发季度绩效自评,季度绩效考核英文自我评价
- B站学习法之深度学习笔记一
- 关于-webkit-的一些用法
- 量子纠缠:万物皆有默契
- 百度算法最新更新介绍之烽火算法
热门文章
- OpenStack进入第二阶段需要解决的“七宗罪”
- Gradle Issue: OutOfMemoryError: PermGen space
- send,recv,sendto,recvfrom
- 设置ComboBox控件的提示内容.
- java中文乱码decode_JAVA中文字符乱码解决详解
- 亚太数学建模竞赛优秀论文_全国大学生数学建模竞赛介绍
- java递归 优点缺点_java编程之递归算法总结
- cadence快捷键修改文件_PCB快捷键设置
- acm java 类库_ACM java入门和基本技巧
- flinksql获取系统当前时间搓_FlinkSQL 动态加载 UDF 实现思路