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 ...
随机推荐
- 投资新兴市场和细分市场 good
新兴市场对程序员来说,就是一种新的语言.一个新的平台.一套新的框架.新兴市场因为刚刚兴起,所以几乎所有人都在同一个起跑线,特别适合后进者.我认识从一个2011年开始学习iOS开发的同学,他能能力中等, ...
- 深入浅出Mybatis系列(八)---mapper映射文件配置之select、resultMap good
上篇<深入浅出Mybatis系列(七)---mapper映射文件配置之insert.update.delete>介绍了insert.update.delete的用法,本篇将介绍select ...
- Struts 和Spring的核心控制器
Struts 核心控制器是FilterDispatch Spring核心控制器是DispatchServlet
- poj1363Rails(栈模拟)
主题链接: id=1363">啊哈哈,点我点我 思路: 这道题就是一道简单的栈模拟. .. .我最開始认为难处理是当出栈后top指针变化了. .当不满足条件时入栈的当前位置怎么办.这时 ...
- 如何解决Android 5.0中出现的警告:Service Intent must be explicit
有些时候我们使用Service的时需要采用隐私启动的方式,但是Android 5.0一出来后,其中有个特性就是Service Intent must be explitict,也就是说从Lollip ...
- VS2015自定义注释内容
一直想自动添加一些注释信息,找了好多种方式:各种插件什么的,最后偶然发现可以修改vs的模板可以做到,下面介绍如何改 首先找到vs的安装目录,如下是我的安装目录: D:\Program Files\VS ...
- CodeForces 452C Magic Trick (排列组合)
#include <iostream> #include <cstdio> #include<cmath> #include<algorithm> us ...
- HDOJ 1308.Is It A Tree?
2015-07-15 问题简述: 给出一组节点关系,判断由这些节点组成的图是否为一颗树. 树只有一个根节点,每个节点只有一条边指向它,没有环. 原题链接:http://poj.org/problem? ...
- python的虚拟运行环境
Python 虚拟环境:Virtualenv 博客分类: Python python 在进行python开发的时候避免不同版本python或python不同版本组件之间的冲突, 有必要配置python ...
- python自学笔记(十)语句与数据结构应用
1.最基本的迭代 for x in y 2.如何迭代字典 for x,y in a.items(): print:x,y 3.如何为字典排序 key_list = a.keys() key_list. ...