B. Random Teams(Codeforces Round 273)
1 second
256 megabytes
standard input
standard output
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+1人。最小的为把人数尽可能均分。即有n%m队为n/m+1,n-n%m队为n/m人,最后
算一下朋友对数,一个队友n人,能够产生n*(n-1)/2队朋友。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
long long n,m;
scanf("%I64d%I64d",&n,&m);
long long mini,maxi;
if(n%m==0)
{
mini=n/m;
mini=mini*(mini-1)/2*m;
}
else
{
long long temp=n%m;
long long k=n/m;
mini=(k*(k-1))/2*(m-temp)+k*(k+1)/2*temp;
}
if(m==1)
maxi=n;
else
maxi=n-m+1;
maxi=maxi*(maxi-1)/2;
printf("%I64d %I64d\n",mini,maxi);
return 0;
}
B. Random Teams(Codeforces Round 273)的更多相关文章
- 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations
题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先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 ...
- 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 ...
- Codeforces Round #273 (Div. 2)
A. Initial Bet 题意:给出5个数,判断它们的和是否为5的倍数,注意和为0的情况 #include<iostream> #include<cstdio> #incl ...
- Codeforces Round #273 (Div. 2) A , B , C 水,数学,贪心
A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- codeforces Codeforces Round #273 (Div. 2) 478B
B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- CODEFORCES ROUND #273 DIV2
题目大意: A简单的说就是,有五个人,他们刚开始有B元,经过一系列过程后,给你他们现在分别有的钱,让你求出B(> <难得的傻逼题啊...但是要注意B是正整数!特判0) B有n个人,要分成m ...
- Codeforces Round #273 (Div. 2)-C. Table Decorations
http://codeforces.com/contest/478/problem/C C. Table Decorations time limit per test 1 second memory ...
- Codeforces Round #273 (Div. 2)-A. Initial Bet
http://codeforces.com/contest/478/problem/A A. Initial Bet time limit per test 1 second memory limit ...
随机推荐
- vue在生产环境清除console.log
在开发环境中我们喜欢用console.log测试代码,但是部署到生产环境我们不可能一个一个把console.log给手动删除了. 在build/webpack.prod.conf.js文件里加上这样一 ...
- P2782 友好城市
P2782 友好城市一道伪装得很好的dp,一开始没想出来,不相交就是所有的都在右边,也就是对于当前的城市i和它的友好城市的坐标都在城市j和它的友好城市的右边,这样就转化成了求最长上升子序列,f[i]表 ...
- cookie之困
参见http://yun.baidu.com/share/link?shareid=1575530779&uk=1795493794 cookie三元组(name,domain,path),它 ...
- Qt判断网络是否在
我们已知的网络连接有3种:拨号.使用局域网以及代理上网. 无论哪一种上网方式都可以判断网络是否畅通,借此,我们来做一个判断网络是否畅通(存在)的程序,新建一个基类为QWidget的工程,不要UI. 添 ...
- Activity-Flag标志位
Activity-Flag标志位 学习自 <Android开发艺术探索> 标志位漫谈 var intent: Intent = Intent(this, Test2Activity::cl ...
- 分位函数(四分位数)概念与pandas中的quantile函数
p分位函数(四分位数)概念与pandas中的quantile函数 函数原型 DataFrame.quantile(q=0.5, axis=0, numeric_only=True, interpola ...
- NOI.AC NOIP模拟赛 第五场 游记
NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ...
- hdu 5781 ATM Mechine dp
ATM Mechine 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 Description Alice is going to take ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...
- 大型电商业务架构 IT大咖说 - 大咖干货,不再错过
大型电商业务架构 IT大咖说 - 大咖干货,不再错过 http://www.itdks.com/dakashuo/new/dakalive/detail/591