Codeforces Round #273 (Div. 2)(B)排列组合
2016-03-10 13:25
351 查看
B. Random Teams
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
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.
Examples
input
output
input
output
input
output
Note
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 2people, maximum
number can be achieved if participants were split on teams of 1, 1 and 4 people.
题意:有n个人,m只队伍,每个队伍至少1人,每个队伍内的人可以俩俩相互称为朋友,问最多,最少有多少对朋友
题解:每个队伍的人数为A[I],那么这支队伍会产生C(A[I],2)对朋友,那么最大的朋友数MAX就是把(n-m)的人数放进一只队伍就是最值了,最小值就是尽可能的将人数平均放进妹纸队伍,求得的和就是最小值、
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define N int(1e5)
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
typedef unsigned long long LL;
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
#ifdef CDZSC
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
int main()
{
#ifdef CDZSC
freopen("i.txt", "r", stdin);
//freopen("o.txt","w",stdout);
int _time_jc = clock();
#endif
LL n,m;
while (~scanf("%lld%lld",&n,&m))
{
LL mx = 0, mi=0;
LL x= (n - m+1);
mx = x*(x - 1) / 2;
LL left = n%m;
x = n / m;
mi = left*(x*(x + 1)) / 2+(m-left)*(x*(x-1))/2;
printf("%lld %lld\n",mi,mx);
}
#ifdef CDZSC
debug("time: %d\n", int(clock() - _time_jc));
#endif
return 0;
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
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.
Examples
input
5 1
output
10 10
input
3 2
output
1 1
input
6 3
output
3 6
Note
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 2people, maximum
number can be achieved if participants were split on teams of 1, 1 and 4 people.
题意:有n个人,m只队伍,每个队伍至少1人,每个队伍内的人可以俩俩相互称为朋友,问最多,最少有多少对朋友
题解:每个队伍的人数为A[I],那么这支队伍会产生C(A[I],2)对朋友,那么最大的朋友数MAX就是把(n-m)的人数放进一只队伍就是最值了,最小值就是尽可能的将人数平均放进妹纸队伍,求得的和就是最小值、
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define N int(1e5)
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
typedef unsigned long long LL;
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
#ifdef CDZSC
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
int main()
{
#ifdef CDZSC
freopen("i.txt", "r", stdin);
//freopen("o.txt","w",stdout);
int _time_jc = clock();
#endif
LL n,m;
while (~scanf("%lld%lld",&n,&m))
{
LL mx = 0, mi=0;
LL x= (n - m+1);
mx = x*(x - 1) / 2;
LL left = n%m;
x = n / m;
mi = left*(x*(x + 1)) / 2+(m-left)*(x*(x-1))/2;
printf("%lld %lld\n",mi,mx);
}
#ifdef CDZSC
debug("time: %d\n", int(clock() - _time_jc));
#endif
return 0;
}
相关文章推荐
- 西普学院web题总结
- git使用代理上网
- Java多线程TCP客户端与服务器间使用Socket通信
- Git 时间,初始版本控制工具
- java中的坑(一)
- 判断字符串里的括号是否匹配
- C++中的find函数
- [dp专题-状态压缩dp] 51nod 1033
- oracle 导入(imp)数据时的表空间(tablespace users)问题
- 看看国外同行,中国独立开发者哭了
- php array to string
- CodeForces - 630O Arrow (数学几何求点的坐标)
- CocoaPods安装流程
- DataGridView拖动到TreeView
- Android中跨进程通讯的4种方式
- 在Eclipse中配置Struts2
- 快速排序的Java语言与C语言实现
- Android开发之发送短信
- 关于MonoDevelop5.9.6_使用总结
- HOJ 1640 Mobile Phone