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

 

Input
5 1
Output
10 10
Input
3 2
Output
1 1
Input
6 3
Output
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的更多相关文章

  1. codeforces 478B Random Teams 解题报告

    题目链接:http://codeforces.com/problemset/problem/478/B 题目意思:有 n 个人,需要将这班人分成 m 个 组,每个组至少含有一个人,同一个组里的人两两可 ...

  2. 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 ...

  3. B. Random Teams(Codeforces Round 273)

    B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. 【CODEFORCES】 B. Random Teams

    B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  5. 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 ...

  6. ACM第六周竞赛题目——B CodeForces 478B

    B - B Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  7. cf478B Random Teams

    B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  8. CF478 B. Random Teams 组合数学 简单题

    n participants of the competition were split into m teams in some manner so that each team has at le ...

  9. CodeForces 478B 第八次比赛 B题

    Description n participants of the competition were split into m teams in some manner so that each te ...

随机推荐

  1. Java I/O theory in system level

    参考文章: JAVA NIO之浅谈内存映射文件原理与DirectMemory Java NIO 2.0 : Memory-Mapped Files | MappedByteBuffer Tutoria ...

  2. DatabaseMetaData的用法(转)

    http://blog.csdn.net/sdliubo/article/details/6546889

  3. Delphi2010的RTTI增强

    Delphi编译的文件体积增大了很多.很大一部分原因是因为Delphi2010默认提供了全信息的RTTI. 每一个数据类型都有全部运行时信息.例如可以在运行时获得结构体的成员以及成员类型等. 这个功能 ...

  4. android中 MediaStore提取缩略图和原始图像

    android中 MediaStore提取缩略图和原始图像 . 欢迎转载:http://blog.csdn.net/djy1992/article/details/10005767 提取图像的Thum ...

  5. SharePoint 2007 (MOSS/WSS) - how to remove "Download a Copy" context menu from a Document Library

    One of my friend and colleague asked me this question. I found it tricky and a good post for my blog ...

  6. Jquery开发插件的方法

    Jquery未开发插件提供了两个方法: (1)Jquery.extend(object)    -为Jquery类本身添加新的方法;代码如下: $.extend({ add:function(a,b) ...

  7. 快速检查SQL两表数据是否一致

    1前话 项目内实现了一新功能:克隆数据库. 2目标 克隆并非用SQLSERVER克隆,故完毕后需要检查各表内一些数据与原表一致性.一些表中的某一些列容许不一致. 3实现 将两表的需要检查的几列取出,相 ...

  8. 浅谈JDBC(二)

    JDBC中的事务 简单来说,事务就是要保证一组DAO方法的操作,要么一起成功要么一起失败. 1.事务控制的位置 在Service中的业务方法内进行事务控制. 2.事务控制的代码 a.注意:JDBC会自 ...

  9. POJ 3974 Palindrome(最长回文子串)

    题目链接:http://poj.org/problem?id=3974 题意:求一给定字符串最长回文子串的长度 思路:直接套模板manacher算法 code: #include <cstdio ...

  10. BZOJ 1497: [NOI2006]最大获利( 最大流 )

    下午到周六早上是期末考试...但是我还是坚守在机房....要挂的节奏啊.... 这道题就是网络流 , 建图后就最大流跑啊跑啊跑... --------------------------------- ...