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 ...
随机推荐
- Oracle基础<5>--触发器
一.触发器 触发器是当特定事件出现时自动执行的代码块.比如,每次对员工表进行增删改的操作时,向日志表中添加一条记录.触发器和存储过程是由区别的:触发器是根据某些条件自动执行的,存储过程是手动条用的. ...
- 转载:Character data is represented incorrectly when the code page of the client computer differs from the code page of the database in SQL Server 2005
https://support.microsoft.com/en-us/kb/904803 Character data is represented incorrectly when the cod ...
- mysql开启general log的方法
因为为了性能考虑,一般general log不会开启.slow log可以定位一些有性能问题的sql,而general log会记录所有的SQL. mysql5.0版本,如果要开启slow log.g ...
- 剑指Offer43 n个骰子点数概率
/************************************************************************* > File Name: 43_Dics.c ...
- entOS查看系统信息-CentOS查看命令
一:查看cpu more /proc/cpuinfo | grep "model name" grep "model name" /proc/cpuinfo 如 ...
- [转]如何制作tizen镜像文件(图文教程)?
http://blog.csdn.net/flydream0/article/details/9163119 之前已讲解了如何下载及编译tizen源码(http://blog.csdn.net/fly ...
- ant 命令学习详解
ant -verbose //输出 ant编译时的详情
- 5059 一起去打CS
5059 一起去打CS 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 早就和lyk约好了去 ...
- JavaScript之简易计算器
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- 【学习笔记】【C语言】指针
一.指针变量的定义 1. 格式:变量类型 *指针变量名; 2. 举例:int *p; char *p2; 3. 注意:定义变量时的*仅仅是指针变量的象征 二.利用指针变量简单修改其他变量的值 1. ...