cf478B-Random Teams 【排列组合】
2015-07-22 18:40
357 查看
http://codeforces.com/problemset/problem/478/B
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.
Input
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.
Output
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.
Sample test(s)
input
output
input
output
input
output
Note
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 2people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.
题解:最小值:均分。最大值:(m-1)个team每个分1个participant,另一个team分(n-(m-1))个participant。
代码:
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.
Input
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.
Output
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.
Sample test(s)
input
5 1
output
10 10
input
3 2
output
1 1
input
6 3
output
3 6
Note
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 2people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.
题解:最小值:均分。最大值:(m-1)个team每个分1个participant,另一个team分(n-(m-1))个participant。
代码:
#include <fstream> #include <iostream> using namespace std; const int N=1000000005; inline __int64 num(int nn){ return (__int64)nn*(nn-1)>>1; } int main(){ //freopen("D:\\input.in","r",stdin); //freopen("D:\\output.out","w",stdout); int n,m; scanf("%d%d",&n,&m); if(n==m) puts("0 0"); else{ int l=n/m,r=n%m; printf("%I64d %I64d\n",num(l+1)*r+num(l)*(m-r),num(n-m+1)); } return 0; }
相关文章推荐
- 移动端尺寸基础知识
- EnvironmentError:mysql config not found
- 十、solr中ik分词器加入同义词配置
- python学习笔记--随时更新
- ECMAScript 6新特性介绍
- 为什么win7 64位的没有debug?cmd中找不到
- Windows8.1优化,解决磁盘100%的问题
- 公历转农历算法
- 今天“农村打工仔”带你们走入Android的世界
- SVN-previous operation has not finished run 'cleanup' if it was interrupted
- 工作经验之OnClick的小细节
- 工作经验之OnClick的小细节
- TextView 使用自定义的字体和亮点
- mysqldump命令详解
- servlet
- Unity3D中的屏幕着色器和图像特效
- Linux读取原Windows磁盘分区
- mysql修改字符编码
- hdu 4738——Caocao's Bridges
- leetcode第231题:Power of Two