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; ...
随机推荐
- Bootstrap 自适应排列顺序
一.前用 我们在做一些页面的设计时,总会想到自适应的问题.其实 Bootstrap 框架就很好的融合这个问题了.下面是我学习 Bootstrap 的总结. 二.问题来源 我为什么会遇见这个问题,是因为 ...
- CodeForces 41A+43A【课上无聊刷水题系列】
41Acode 好像只要前一个字符串存在下一个字符串的头单词就YES: #include <bits/stdc++.h> using namespace std; typedef __in ...
- unity常用插件
Unity3D常用插件,网址:http://jingyan.baidu.com/article/7f766daf4ef2844100e1d079.html ,想想自己也有小半年unity经验了,于是整 ...
- Win7下Intellij开发Scala环境搭建
1.Scala下载并安装 1.Scala的安装时需要依赖JDK的,目前我的电脑上,jdk是已经安装好了,这里就不再说明 2.在地址http://www.scala-lang.org/download/ ...
- python_argparse
使用python argparser处理命令行参数 #coding:utf-8 # 导入模块 import argparse # 创建ArgumentParser()对象 parser = argpa ...
- layui 单选框选中事件
<div class="layui-form-item" pane=""> <label class="layui-form-lab ...
- Gym - 101810B ACM International Collegiate Programming Contest (2018)
bryce1010模板 http://codeforces.com/gym/101810 #include <bits/stdc++.h> using namespace std; #de ...
- centos下svn的ldap认证配置
前提:完成svn的基本安装 一.安装sasl相关组件 #yum install -y cyrus-sasl cyrus-sasl-lib cyrus-sasl-plain 二.查看SASL版本和提供的 ...
- java中的线程安全是什么?什么叫线程安全?什么叫不安全?
java中的线程安全是什么: 就是线程同步的意思,就是当一个程序对一个线程安全的方法或者语句进行访问的时候,其他的不能再对他进行操作了,必须等到这次访问结束以后才能对这个线程安全的方法进行访问 什么叫 ...
- js获取select下拉框选项的值
var onchange="getBatch(this.options[this.options.selectedIndex].value)"