cf478B Random Teams
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.
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.
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.
5 1
10 10
3 2
1 1
6 3
3 6
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*(n-1)/2。求最大值和最小值
显然前面取m-1组的1最后一组最大的方案是答案最大
平均分的方案是答案最小
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL a,b,c,d,e;
int main()
{
a=read();b=read();
c=(a-b+)*(a-b)/;
d=(a-b*(a/b));
e=(d)*(a/b+)*(a/b)/+(b-d)*(a/b)*(a/b-)/;
printf("%lld %lld\n",e,c);
}
cf478B
cf478B Random Teams的更多相关文章
- codeforces 478B Random Teams
codeforces 478B Random Teams 解题报告 题目链接:cm.hust.edu.cn/vjudge/contest/view.action?cid=88890#probl ...
- 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
http://codeforces.com/contest/478/problem/B B. Random Teams time limit per test 1 second memory limi ...
- 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 ...
- CF478 B. Random Teams 组合数学 简单题
n participants of the competition were split into m teams in some manner so that each team has at le ...
- Random Teams
n participants of the competition were split into m teams in some manner so that each team has at le ...
- codeforces 478B Random Teams 解题报告
题目链接:http://codeforces.com/problemset/problem/478/B 题目意思:有 n 个人,需要将这班人分成 m 个 组,每个组至少含有一个人,同一个组里的人两两可 ...
- cf478B-Random Teams 【排列组合】
http://codeforces.com/problemset/problem/478/B B. Random Teams n participants of the competition w ...
随机推荐
- jQuery Ajax 实例 ($.ajax、$.post、$.get)转
Jquery在异步提交方面封装的很好,直接用AJAX非常麻烦,Jquery大大简化了我们的操作,不用考虑浏览器的诧异了. 推荐一篇不错的jQuery Ajax 实例文章,忘记了可以去看看,地址为:ht ...
- mysql 中 LIMIT的简单用法
mysql--语法: SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset --举例: select * from table l ...
- 《Algorithms 4th Edition》读书笔记——2.4 优先队列(priority queue)-Ⅶ(延伸:堆排序的实现)
2.4.5 堆排序 我们可以把任意优先队列变成一种排序方法.将所有元素插入一个查找最小元素的有限队列,然后再重复调用删除最小元素的操作来将他们按顺序删去.用无序数组实现的优先队列这么做相当于进行一次插 ...
- 诺心(LECAKE) | 氪加
诺心(LECAKE) | 氪加 诺心(LECAKE)
- Python Open Flash Chart (pyOFC2) — Home
Python Open Flash Chart (pyOFC2) - Home pyOFC2 Python Open Flash Chart 2
- C#中通过位运算实现多个状态的判断
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- php 依据字符串生成相应数组方法
php 依据字符串生成相应数组方法 比如: <?php $config = array( 'project|page|index' => 'content', 'project|page| ...
- progressbar使用方法:进度画面大小,进度画面背景,进度百分比
前一段时间,因为项目须要研究了下progressbar,发现这个小东西还真是不简单.在这个小控件的显示效果上,花费的时间远大于预估的工作量.话说程序猿一直是这样,预估的工作量远少于实际... ...
- Android 打造自己的个性化应用(三):应用程序的插件化
在android的项目开发中,都会遇到后期功能拓展增强与主程序代码变更的现实矛盾,也就是程序的灵活度. 由于linux平台的安全机制,再加上dalvik的特殊机制,各种权限壁垒,使得开发一个灵活多变的 ...
- 适用于CSS2的各种运动的javascript运动框架
<script> window.onload = function() { //var oDiv1 = document.getElementById('box1'); //var oDi ...