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 ...
随机推荐
- 《算法导论》习题解答 Chapter 22.1-8(变换邻接表的数据结构)
一般散列表都与B+树进行比较,包括在信息检索中也是. 确定某条边是否存在需要O(1). 不足: (1)散列冲突. (2)哈希函数需要不断变化以适应需求. 另外:B+树.(见第18章) 与散列表相比的不 ...
- 【转】驱动中的类class和节点
原文出处:http://blog.chinaunix.net/uid-23036581-id-2230558.html 一个类是一个设备的高级视图, 它抽象出低级的实现细节. 驱动可以见到一个SCSI ...
- python 基础——变量
变量赋值 1. 把任意类型的变量[名称]赋值给新的变量,总是增加对象引用,而不是创建新的对象 2. 对于list.dict可变类型,操作的都是同一个对象 3. 使用del删除的是该对象的一个引用,只有 ...
- POJ 2236 Wireless Network (并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 18066 Accepted: 761 ...
- 剑指Offer21 二叉树的层序遍历
/************************************************************************* > File Name: 21_PrintT ...
- tornado 信号处理
一般情况下,对于线上的程序,我们是不能采取kill -9 来杀掉进程的 因为程序可能有未处理完的程序,如果贸然采取kill -9可能会导致数据不一致 如果需要关闭程序怎么办呢,一般情况下我们采取信号技 ...
- NodeJS学习之异步编程
NodeJS -- 异步编程 NodeJS最大的卖点--事件机制和异步IO,对开发者并不透明 代码设计模式 异步编程有很多特有的代码设计模式,为了实现同样的功能,使用同步方式和异步方式编写代码会有很大 ...
- Sql Server Row_Number() 学习
Row_Number(): row_number()主要是为选出的每一条记录按照一定的排序方式生成一个行序号. 语法: ROW_NUMBER ( ) OVER ( [ PARTITION BY val ...
- log4net自定义字段写入SqlServer数据库 ASP.net
首先申明,本示例经过本作者亲自试验通过,可以运行 第一步 编写log4net配置文件 此处为Log.xml,该文件放在与Web.config平级的位置 <?xml version="1 ...
- (转)Linux下Oracle启动、建立表空间、用户、授权、数据库导入导出
Linux系列 启动1.启动数据库实例,分为两步:第一步,启动监听:第二步,启动数据库实例. 1.1进入到sqlplus启动实例 [oracle@redhat ~]$ su - oracle ...