Codeforces-273(div2) B. Random Teams
来源:互联网 发布:软件系统架构ppt 编辑:程序博客网 时间:2024/04/20 01:03
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个队进行比赛,比赛完之后每个队里人成为朋友,现在让我们求最少有多少对朋友,最少有多少对朋友。
做法:假设一个队里有x个人,那么所产生的朋友对数就是x-1+x-2+...+1,也就是(x-1+1)*(x-1)/2;要使朋友对数最多,那么最优的解决方案应该是(m-1)队都是1人一队,然后剩下的(n-(m-1))人为一队;使朋友对数最少,就要让n个人平摊到m个队伍上,所以有(res=n-n/m*m)个队伍是(n/m+1)个人,(m-res)个队伍是(n/m)个人,最后分别算出最大值和最小值就是答案。
#include <iostream>#include <cstdio>#include <climits>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include<map>#include <algorithm>#include<ctime>#define esp 1e-6#define LL unsigned long long#define inf 0x0f0f0f0fusing namespace std;int main(){__int64 n,m,min1,max1,tt,kk;__int64 sl,mm,res;while(scanf("%I64d%I64d",&n,&m)!=EOF){tt=n;kk=m;res=0;min1=max1=0;if(n%m==0){mm=n/m;min1=m*(mm*(mm-1)/2);}else{mm=n/m;res=n-n/m*m;min1=res*((mm+1)*(mm)/2);min1+=(m-res)*(mm*(mm-1)/2);}n=tt;m=kk;max1=((n-(m-1))*((n-(m-1))-1)/2);printf("%I64d %I64d\n",min1,max1);}return 0;}
- Codeforces-273(div2) B. Random Teams
- Codeforces Round #273(Div2) B. Random Teams 贪心+数学
- 【CODEFORCES】 B. Random Teams
- B. Random Teams(Codeforces Round 273)
- B. Random Teams(Codeforces Round 273)
- codeforces-#478B. Random Teams
- Codeforces 478B. Random Teams
- Codeforces 478B Random Teams
- Codeforces 478B Random Teams
- codeforces 478B Random Teams
- Codeforces Round #273 (Div. 2) --B Random Teams
- Codeforces 478B Random Teams(组合数学)
- Random Teams(Codeforces Round 273)
- CF 273B Random Teams
- codeforces-#478B. Random Teams 排列组合
- B. Random Teams
- 478B. Random Teams
- B. Random Teams
- [linux驱动]linux块设备学习笔记(三)
- Drupal 7.31 SQL注入分析及POC
- ios 企业应用"无法安装应用程序 因为证书无效"的解决方案
- 【小企】哪些有你喜欢的座右铭呢
- javascript Date Format 函数
- Codeforces-273(div2) B. Random Teams
- 搭建WebService简易框架示例
- uva--331+dfs+回溯
- 数据库学习3——mysql5.6启动占用内存很大的解决方法
- python的学习---- ftplib模块 .
- 5.2.1 F# 和 C# 中的多值
- 一个程序员的书法学习之路-选笔篇
- windows影音制作工具安装教程
- C# 计算字符串的哈希值(MD5、SHA)