codeforces 478B Random Teams
codeforces 478B Random Teams 解题报告
题目链接:cm.hust.edu.cn/vjudge/contest/view.action?cid=88890#problem/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
Sample Output
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 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.
题意:
n个人分成m队(每队至少一人),竞赛结束后,其中来自同一队的任意两个人可以成为朋友。求最多和最少可以组成多少队朋友?
分析:
排列组合问题。最少:n个人平均分到m个队,组成的队数最少。如果不能平分(即n%m!=0),则将剩下的人平均分到每个组。
最多:m-1个队只有一个人,剩下的人全部在一个队中。
代码:
#include<cstdio>
#include<iostream>
using namespace std; int main()
{
long long n,m;
long long kmin,kmax;
scanf("%I64d%I64d",&n,&m);
long long a=n/m,b=n%m;
if(b==)//可以平均分(最少)
kmin=m*a*(a-)/;
else //不能平均分(最少)
kmin=(m-b)*a*(a-)/+b*a*(a+)/;
kmax=(n-m+)*(n-m)/;//最多
printf("%I64d %I64d\n",kmin,kmax);
return ;
}
codeforces 478B Random Teams的更多相关文章
- codeforces 478B Random Teams 解题报告
题目链接:http://codeforces.com/problemset/problem/478/B 题目意思:有 n 个人,需要将这班人分成 m 个 组,每个组至少含有一个人,同一个组里的人两两可 ...
- Codeforces Round #273 (Div. 2)-B. Random Teams
http://codeforces.com/contest/478/problem/B B. Random Teams time limit per test 1 second memory limi ...
- B. Random Teams(Codeforces Round 273)
B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 【CODEFORCES】 B. Random Teams
B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #273 (Div. 2) B . Random Teams 贪心
B. Random Teams n participants of the competition were split into m teams in some manner so that e ...
- ACM第六周竞赛题目——B CodeForces 478B
B - B Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- cf478B Random Teams
B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- CF478 B. Random Teams 组合数学 简单题
n participants of the competition were split into m teams in some manner so that each team has at le ...
- CodeForces 478B 第八次比赛 B题
Description n participants of the competition were split into m teams in some manner so that each te ...
随机推荐
- js判断某个方法是否存在
window.onload = function(){ try{ if(test && typeof(test) == "function"){ test(); } ...
- Spring 装配Bean
Spring 装配Bean 装配解释: 创建应用对象之间协作关系的的行为通常称为装配(wiring),这也是依赖注入的本质 依赖注入是Spring的基础要素 一 : 使用spring装配Bean基础介 ...
- OSG消锯齿
osg::DisplaySettings::instance()->setNumMultiSamples(); 在osg+mfc下成功实现抗锯齿,在程序初始化的时候,即在osg控制类中,我的 ...
- Codeforces 711E ZS and The Birthday Paradox(乘法逆元)
[题目链接] http://codeforces.com/problemset/problem/711/E [题目大意] 假设一年有2^n天,问k个小朋友中有两个小朋友生日相同的概率. 假设该概率约分 ...
- Delegation事情委托或代理
在javasript中delegate这个词经常出现,看字面的意思,代理.委托.那么它究竟在什么样的情况下使用?它的原理又是什么?在各种框架中,也经常能看到delegate相关的接口.这些接口又有什么 ...
- UVA122-Trees on the level(链二叉树)
Trees on the level Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Sub ...
- HDU 11488 Hyper Prefix Sets (字符串-Trie树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
- tar.xz文件怎样解压
XZ压缩最新压缩率之王 xz这个压缩可能非常多都非常陌生,只是您可知道xz是绝大数linux默认就带的一个压缩工具. 之前xz使用一直非常少,所以差点儿没有什么提起. 我是在下载phpmyadmin的 ...
- MongoDB(三)mongoDB下载和安装
软件下载 下载mongodb最新的包:http://www.mongodb.org/downloads 下载mongodb可视化界面,mongoVUE:http://download.csdn.net ...
- c/c++ double的数字 转成字符串后 可以有效的避免精度要求不高的数
char n[100]; sprintf(n,"%lf",db);