CF478 B. Random Teams 组合数学 简单题
n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.
The only line of input contains two integers n and m, separated by a single space (1 ≤ m ≤ n ≤ 109) — the number of participants and the number of teams respectively.
The only line of the output should contain two integers kmin and kmax — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.
5 1
10 10
3 2
1 1
6 3
3 6
In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.
虽然是道水题,但是我还是想说下。
题意:已知∑ai=n(i从1到m),求∑C(2,ai)的最大值和最小值
要求ai>=1
化简:原式=(∑(ai^2)-n)/2
所以只要求出∑(ai^2)的最值即可
考虑我们分配2个数x,y,根据贪心:
x^2+y^2<=(x-1)^2+(y+1)^2 (x<y)
所以要让平方和更大,我们应该从x中拿更多的给y,最终就是x=1,y尽量大
y再和其他数比较,也是同样的结果,最终,我们得到:
当m-1个为1,1个为n-m+1的时候,得到最大值
同理,当m个数尽量平均的时候,就得到最小值。
#include<cstdio>
#include<iostream> #define LL long long using namespace std; int main()
{
LL n,m;
cin>>n>>m;
LL tmax=,tmin=;
tmax=m-+(n-m+)*(n-m+);
LL a=n/m;
LL b=n%m;
int i=;
tmin=b*(a+)*(a+)+(m-b)*(a*a); cout<<(tmin-n)/<<" "<<(tmax-n)/<<endl;
return ;
}
CF478 B. Random Teams 组合数学 简单题的更多相关文章
- 【CODEFORCES】 B. Random Teams
B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- BZOJ 2683: 简单题
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 913 Solved: 379[Submit][Status][Discuss] ...
- 【BZOJ-1176&2683】Mokia&简单题 CDQ分治
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 821[Submit][St ...
- Bzoj4066 简单题
Time Limit: 50 Sec Memory Limit: 20 MBSubmit: 2185 Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...
- Bzoj2683 简单题
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1071 Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...
- 这样leetcode简单题都更完了
这样leetcode简单题都更完了,作为水题王的我开始要更新leetcode中等题和难题了,有些挖了很久的坑也将在在这个阶段一一揭晓,接下来的算法性更强,我就要开始分专题更新题目,而不是再以我的A题顺 ...
- [BZOJ2683][BZOJ4066]简单题
[BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...
- HDU 1753 大明A+B(字符串模拟,简单题)
简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...
- 团体程序设计天梯赛-练习集L1-014. 简单题
L1-014. 简单题 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 这次真的没骗你 —— 这道超级简单的题目没有任何输入. ...
随机推荐
- php支付接口,代付、感悟
支付接口: 1.验证用户登录信息 2.验证参数.用加密串来匹配,开信息是否被篡改 3.如果有必要可以仿造购物城 建立购物车列表 4.建立和请求方的关联表 5.进行订单生成.支付流程.各种判断.验证. ...
- 课堂所讲整理:HTML--6运算符、类型转换
1.类型转换: 分为自动转换和强制转换,一般用强制转换. 其他类型转换为整数:parseint(): 其他类型转换为小数:parsefloat(): 判断是否是一个合法的数字类型:isNaN(): 是 ...
- IE 下加载jQuery
转:http://www.iitshare.com/ie8-not-use-native-json.html 解决在IE8中无法使用原生JSON的问题 起因 在项目中要将页面上的js对象传给后台, ...
- IL-rewriting profiler
https://blogs.msdn.microsoft.com/davbr/2007/03/06/creating-an-il-rewriting-profiler/ https://blogs.m ...
- 递归遍历多维数组(树数据结构)的超级简单方式,并且可以递归超过200层,摘自<<PHP精粹:编写高效PHP代码>>
<?php $array = array( "Hello", // Level 1 array( "World" // Level 2 ), array( ...
- Git-仓库迁移
如果你想从别的 Git 托管服务那里复制一份源代码到新的 Git 托管服务器上的话,可以通过以下步骤来操作.1). 从原地址克隆一份裸版本库,比如原本托管于 GitHub. git clone --b ...
- Android调用系统分享功能以及createChooser的使用
工程结构 //效果图 点击测试分享 ...
- linux oracle profile配置
[oracle@db01 ~]$ more .bash_profile # .bash_profile # Get the aliases and functionsif [ -f ~/.bashrc ...
- 20150914 异常语句 math的方法 去空格 索引
异常语句 int cuo = 0; Console.WriteLine("请输入:"); string s = Console.ReadLine(); try { DateTime ...
- 028. asp.net数据绑定控件值DataList控件
DataList控件可以使用模板与定义样式来显示数据并进行数据的选择, 删除及编辑工作. DataList控件的最大特点是一定要通过模板来定义数据的显示格式. 如果要设计出美观的界面, 就需要花费一番 ...