【Codeforces Round 273 (Div 2)B】【贪心】 Random Teams n人分m组,可形成的最小朋友数和最大朋友数
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int n,m;
int main()
{
while(~scanf("%d%d",&n,&m))
{
LL num0=n/m;
LL team0=m-n%m;
LL num1=num0+1;
LL team1=n%m;
LL minv=team0*num0*(num0-1)/2+team1*num1*(num1-1)/2;
LL num=(n-m+1);
LL maxv=num*(num-1)/2;
printf("%lld %lld\n",minv,maxv);
}
return 0;
}
/*
【题意】
给你n和m,有1<=m<=n<=1e9,表示有n个人要分到m组当中去。
每个组至少要分一人,每个组内的每两个人都会成为朋友。
问你如何分组,可以得到最小朋友对数和最大朋友对数,并输出。
【类型】
贪心
【分析】
显然——
最小朋友对数,取自分配最平均的情况
最大朋友对数,取自分配最极端的情况
依次算出来即可。
【时间复杂度&&优化】
O(1)
*/