CodeForces 478B 第八次比赛 B题
Description
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 Input
5 1
10 10
3 2
1 1
6 3
3 6
Hint
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.
题意:有n个选手和m个队伍,让你分配,条件是每个队伍至少要有1个选手。分配完之后,每队伍里2个人可以组成一组,求分配完之后最多的组数和最少的组数....
题解:只要考虑怎么分最多,怎么分最少就好了
1. 最多的情况就是,先每个队伍分一个人,然后把剩下的全部给到一个队伍里,就是最多的情况 例如:n=10,m=3
1 1 8
2、 最少的情况就是,每队分n/m个人,然后剩下的再一个一个的分给每队。 例如
3 3 3+1
代码如下:
#include <stdio.h>
int main()
{
int n,m;
long long kmin=,kmax=;
scanf("%d%d",&n,&m);
int d=n-m+; //因为把剩下的全部分到一队中的那只队伍里原来就存在一个人了,所以要加1
//printf("d=%d\n",d);
for(int i=d; i>d-; i--) //这里手贱 用了循环 其实直接就可以乘出来 这里相当于 在d人中中取两个出来(下面的是一样的)
{
kmax*=i;
//printf("kmax=%d\n",kmax);
}
kmax/=;
int x=n/m; //每队均分到多少人
int s=n%m; //剩下的人
for(int i=x; i>x-; i--)
{
kmin*=i;
//printf("kmin=%d\n",kmin);
}
kmin/=;
kmin*=m; //因为是均分,所以一队的分组情况乘以m就是目前所有的
kmin+=s*x; //最后还要加上,剩下的人,每队给一个直到没有情况。 可以想一下,如果在原来的有x个人的队伍中在家上一个,就会多出来x中取两个的情况,所以这里还剩下s个人,就会多出s*x种
printf("%lld %lld\n",kmin,kmax);
}
CodeForces 478B 第八次比赛 B题的更多相关文章
- CodeForces 569A 第八次比赛 C题
Description Little Lesha loves listening to music via his smartphone. But the smartphone doesn't hav ...
- CodeForces 478B 第六周比赛B题
B - B Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Descriptio ...
- LightOJ 1317 第八次比赛 A 题
Description You probably have played the game "Throwing Balls into the Basket". It is a si ...
- ACM第六周竞赛题目——B CodeForces 478B
B - B Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- codeforces 478B Random Teams
codeforces 478B Random Teams 解题报告 题目链接:cm.hust.edu.cn/vjudge/contest/view.action?cid=88890#probl ...
- CSDN挑战编程——《金色十月线上编程比赛第二题:解密》
金色十月线上编程比赛第二题:解密 题目详情: 小强是一名学生, 同一时候他也是一个黑客. 考试结束后不久.他吃惊的发现自己的高等数学科目竟然挂了,于是他果断入侵了学校教务部站点. 在入侵的过程中.他发 ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- Codeforces 1082B Vova and Trophies 模拟,水题,坑 B
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
随机推荐
- android开发之路12(android四大组件&Fragment&AsyncTask类)
一.Activity组件1.简介:Activity组件是Android四大组件之一,通常一个Activity相当于一个用户界面,我们可以通过加载布局文件将Android提供的各种控件及自定义控件显示到 ...
- Precompile Prefix file(.pch文件)
参考资料: http://blog.csdn.net/lwjok2007/article/details/46385595 http://www.tuicool.com/articles/beURbe ...
- POJ 1182 食物链 (并查集)
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 50601 Accepted: 14786 Description ...
- hdu 3062 2-SAT问题
思路:裸的2-SAT. #include<map> #include<set> #include<cmath> #include<queue> #inc ...
- Bootstrap 小技巧以及相关资源整理
1, Bootstrap Bundle (http://bootstrapbundle.com/): 提供了15中不同的MVC Bootstrap模板.[扩展和更新]中搜索“Bootstrap Bu ...
- js里正则表达式详解
详细内容请点击 正则表达式中的特殊字符 字符 含意 \ 做为转意,即通常在"\"后面的字符不按原来意义解释,如/b/匹配字符"b",当b前面加了反斜杆后/\b/ ...
- UI设计之PS界面初始化设置
一.PS界面初始化 1.新建设置 web设计的基础标准:宽度为1920px,高度自定义,分辨率72px,背景模式RGB 8位.(提示:可以“存为预设”以便以后直接调用) 注意:背景内容为透明!!! ...
- Android ListView动态改变Item高度
在adapter的getView方法中进行设置,代码如下 @Override public View getView(int position, View convertView, ViewGroup ...
- win8升级win10后的windows.old怎么删除
现在win10只是出了预览版本,还没有出正式版,但是相信一部分朋友都与小D一样,喜欢尝鲜,已上用上了win10了. 有些人是通过win8或是8.1直接安装升级上去的,这样操作是安装方便,但是系统会为了 ...
- 【学习笔记】【C语言】指向函数的指针
每个函数都有自己的内存地址,指针保存了函数的地址后就能指向函数了. #include <stdio.h> double haha(double d, char *s, int a) { } ...