当前位置:网站首页>A. Berland Poker &1000【简单数学思维】
A. Berland Poker &1000【简单数学思维】
2022-07-03 17:48:00 【Codiplay】
题目描述:
n张卡片中有m个王,一共k个人打牌。每个人取n/k张牌(保证整除),将最大和次大间的差值最大化(提炼后的)
错误思路:
坚决杜绝:if....输出一个答案;if......输出答案
正解:
像解数学题一样解出来,如果要得到答案,我需要哪些要素?对于这些要素再逐个击破。
其实将最大和次大间的差值最大化这样的提炼已经能帮助我解题了。
最大值直接能定下来,要么是m,要么是n / k。最大值同时小于等于二者,所以要取min。
当最大值确定下来后,次大值同理,有一个上取整的操作。
int theirs = (m - our + k - 2) / (k - 1);//对谁上取整,加上分母-1
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
cin >> t;
while(t -- ){
int n, m, k;
cin >> n >> m >> k;
int our = min(n / k, m);
int thiers = (m - our) / (k - 1);
//手工上取整
if((m - our) % (k - 1) != 0) {
thiers ++;
}
cout << our - thiers << '\n';
}
return 0;
}
边栏推荐
- Research on Swift
- Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code
- Gear2021 monthly update - December
- Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028
- 1146_ SiCp learning notes_ exponentiation
- TensorBoard快速入门(Pytorch使用TensorBoard)
- Micro service component sentinel console call
- Where is the database account used when running SQL tasks in data warehouse tasks configured
- PHP returns 500 errors but no error log - PHP return 500 error but no error log
- Remote office tools sharing | community essay solicitation
猜你喜欢
Micro service component sentinel console call
IntelliJ 2021.3 short command line when running applications
Implementation of Tetris in C language
Five problems of database operation in commodity supermarket system
一入“远程”终不悔,几人欢喜几人愁。| 社区征文
1147_ Makefile learning_ Target files and dependent files in makefile
Talk about the design and implementation logic of payment process
(9) Opencv Canny edge detection
Hongmeng fourth training
POM in idea XML graying solution
随机推荐
(9) Opencv Canny edge detection
IntelliJ 2021.3 short command line when running applications
(8) HS corner detection
TensorBoard快速入门(Pytorch使用TensorBoard)
How to purchase Google colab members in China
Mathematical formula (test)
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
Play with fancy special effects. This AE super kit is for you
Automata and automatic line of non-standard design
Select 3 fcpx plug-ins. Come and see if you like them
How to deploy applications on kubernetes cluster
Golang unit test, mock test and benchmark test
How to install PHP on Ubuntu 20.04
企业级自定义表单引擎解决方案(十一)--表单规则引擎1
自动渗透测试工具核心功能简述
基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
Type conversion, variable
Test your trained model
Comparison of kotlin collaboration + retro build network request schemes
微服务组件Sentinel控制台调用