Codeforces Round #273 (Div. 2)-B. Random Teams
http://codeforces.com/contest/478/problem/B
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个房间,最多能有几对朋友,最多的情况就是除了一个房间之外的其他房间都只有一个人,剩下的所有人在一个房间
最少的情况就是将所有的人尽可能平均分配到每一个房间
求组合数C(2, n) = n * (n - 1) / 2;
1 #include <stdio.h>
2
3 int main(){
4 long long n, m, kmin, kmax, res;
5 while(scanf("%I64d %I64d", &n, &m) != EOF){
6 if(n % m == ){
7 res = n / m;
8 kmin = m * res * (res - ) / ;
9 }
else{
res = n / m;
kmin = (n % m) * res * (res + ) / + (m - n % m) * res * (res - ) / ;
}
n = n - m + ;
kmax = n * (n - ) / ;
printf("%I64d %I64d\n", kmin, kmax);
}
return ;
20 }
Codeforces Round #273 (Div. 2)-B. Random Teams的更多相关文章
- 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) 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)
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 #247 (Div. 2) D. Random Task
D. Random Task time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 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 ...
- Codeforces Round #246 (Div. 2) A. Choosing Teams
给定n k以及n个人已参加的比赛数,让你判断最少还能参加k次比赛的队伍数,每对3人,每个人最多参加5次比赛 #include <iostream> using namespace std; ...
随机推荐
- cell内存优化
UITableView的常用属性: 分割线颜色设置: 1> 设置separatorStyle: 分割线的颜色 方法:tableView.separatorStyle = UITableViewC ...
- C#连接Sqlite实现单表操作
今天我们来了解下VS使用的众多数据库中比较轻量的数据库SQLITE,好处当然就在于“轻~”!!!.自己理解
- bzoj1339/1163:[Baltic2008]Mafia
传送门 最小割,割点,模板... 代码: #include<cstdio> #include<iostream> #include<algorithm> #incl ...
- python错误之RuntimeError: dictionary changed size during iteration
pythonn报错信息: C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/Ad ...
- 洛谷1052(路径压缩后简单dp)
同POJ3744写法都是一样的. 距离太长无意义可以压缩,注意不是随便压的,想一想可以跟%T发生关系. #include <cstdio> #include <cctype> ...
- 关于pycharm的一个imoprt的随笔
近来发现pycharm一个方便的地方,from 文件夹名.组件名 import 方法(引入和父级目录同级文件夹下的模块),在pycharm中这种引用是能够成功的,但是在python自带的IDLE中不能 ...
- 将GitLab上面的代码克隆到本地
1.安装GitLab客户端 2.去GitLab服务端找项目路径 3.去GitLab客户端去克隆代码 右键-->git Clone 4.最后结果
- jmeter压力测试中遇到的问题汇总
1.线程数大于1的时候,计数器配置没有勾选reset counter选项,导致测试结果出错 正常结果: 实际结果:index大于count数量时出错,病区及床号直接显示在count的基础上开始加1了 ...
- CImage访问像素及其像素操作总结
MSDN的代码 COLORREF pixel; int maxY = imgOriginal.GetHeight(), maxX = imgOriginal.GetWidth(); byte r,g, ...
- Nacos部署中的一些常见问题汇总
开个帖子,汇总一下读者经常提到的一些问题 问题一:Ubuntu下启动Nacos报错 问题描述 使用命令sh startup.sh -m standalone启动报错: ./startup.sh: 78 ...