CodeForces 478B 第六周比赛B题
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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支队伍中去,每支队伍至少要有一个人,在一个队伍中的任意两个人都可以成为一对朋友,要你分配队伍,求出最少能够形成的朋友对数min,和最多能形成的队伍对数max.
思路:
当m=1的时候,也就是只有一支队伍,那么kmin=kmax=C(n,2);其余的情况求最大值的 时候我我们先把每个队伍分配一个人,然后把剩余的人全部分配到一个队伍,这样求得的为最大值,max=C(n-m+1,2),求最小值的时候,我们先把每个队伍都平均分配人数,剩余的人在任意选几个放一个人。
#include<iostream>
using namespace std;
int main()
{
long long minnum,maxnum,n,u,m,t,s,p;
cin>>n>>m;
if(m==)
{
minnum= maxnum=n*(n-)/;
cout<<minnum<<" "<<maxnum<<endl;
}
else
{
t=n/m;
p=n-t*m;
minnum=(m-p)*t*(t-)/+p*t*(t+)/;
u=n-m+;
maxnum=u*(u-)/;
cout<<minnum<<" "<<maxnum<<endl;
}
}
CodeForces 478B 第六周比赛B题的更多相关文章
- CodeForces 569A 第六周比赛C踢
C - C Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- CodeForces 478B 第八次比赛 B题
Description n participants of the competition were split into m teams in some manner so that each te ...
- LightOJ 1317 第六周比赛A题
A - A Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Description Y ...
- HDU2669 第六周练习I题(扩展欧几里算法)
第六周练习I题 I - 数论,线性方程 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- Codeforces 559A 第六周 O题
Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...
- 第十六周oj刷题——Problem I: 改错题:类中私有成员的訪问
Description 改错题: 设计一个日期类和时间类,并编写全局函数display用于显示日期和时间. 要求:display函数作为类外的普通函数,而不是成员函数 在主函数中调用display函数 ...
- 第十六周oj刷题——Problem E: B 构造函数和析构函数
Description 在建立类对象时系统自己主动该类的构造函数完毕对象的初始化工作, 当类对象生命周期结束时,系统在释放对象空间之前自己主动调用析构函数. 此题要求: 依据主程序(main函数)和程 ...
- 暑假集训第一周比赛C题
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83146#problem/C C - 学 Crawling in process... C ...
- CodeForces 569A 第八次比赛 C题
Description Little Lesha loves listening to music via his smartphone. But the smartphone doesn't hav ...
随机推荐
- O - Extended Traffic(判断负环)
题意:有n个城市,每一个城市有一个拥挤度ai,从一个城市I到另一个城市J的时间为:(aJ-aI)^3,存在负环.问从第一个城市到达第k个城市所话的时间,如果不能到达,或者时间小于3输出?否则输出所花的 ...
- SQL随笔
多表分页查询: ,; 向表中插入新的字段: ALTER TABLE `Table_name` ) NOT NULL DEFAULT '' AFTER `id`; 更新表数据: UPDATE [LOW ...
- redis 集群
http://www.linuxidc.com/Linux/2015-08/121845.htm Redis3.0版本之后支持Cluster,具体介绍redis集群我就不多说,了解请看redis中文简 ...
- 深入了解JavaScript中的for循环
在ECMAScript5中,有三种for循环,分别是: 简单for循环 for-in forEach 在ES6中,新增了一种循环 for-of 简单for循环 const arr = [1, 2, 3 ...
- dubbo源码分析一:整体分析
本文作为dubbo源码分析的第一章,先从总体上来分析一下dubbo的代码架构.功能及优缺点,注意,本文只分析说明开源版本提供的代码及功能. 1.dubbo的代码架构: spring适配层:常规的sp ...
- Prefix.pch的作用和用法
一般用于放置宏,省去xcode编译的时间 Hello World_Prefix.pch:扩展名.pch表示"precompiled header",这是一个你工程要用到的来自于外部 ...
- ckfinder 1
网上的破解教程对于2.4版本来说已经过时了. 以下是CKFinder 2.4 ASP.NET的亲测可用破解方法,经测试,只需修改两处代码. 打开ckfinder.js, 步骤1. 搜索替换如下代码: ...
- Swift中FDMB的使用(增、删、改、查)
直接上代码: import UIKit class ZWDBManager: NSObject { //前提将FMDBDatabase的头文件增加到桥接文件里 var dataBase:FMDatab ...
- jni java和C之间的值传递(int String int[])
我们通过jni调用C代码不可能每次只是去调一个方法,通常,我们需要传递一些值过去. 例如,播放电影,那就肯定需要你把电影的 url给 C的播放器吧,等等. 接下来就看一看怎么去传递这些值: 首先是最简 ...
- 诡异的TNS-12541:TNS:nolistener
诡异的TNS-12541:TNS:nolistener OS:Microsoft Windows 2003 Ent ...