Codeforces Round 273 Random Teams 解题心得

原题:

Description

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.

Sample Input

Input

5 1

Output

10 10

Input

3 2

Output

1 1

Input

6 3

Output

3 6

Hint

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.

分析:

一个队所组成的朋友是Cn 2     也就是n+(n-1)+(n-2)+....+1

细心想想就会知道

保证每个队有一个人,把所有剩下的人都几种到一个队的时候朋友数最多,

尽量平均分的朋友数最少

依据这个来写代码:

#include <stdio.h>
#include <iostream>
using namespace std;
long long jie(long long x)
{
    return (x*(x - 1)) / 2;
}
int main()
{
    long long n, m, minn, maxn;

    scanf("%lld%lld", &n, &m);

    long x = n / m;
    long y = n%m;
    if (m == 1)
        minn = jie(n);
    else
        minn = y*jie(x + 1) + (m - y)*jie(x);
    maxn = jie(n - m + 1);

    printf("%lld %lld\n", minn, maxn);

    return 0;
}
时间: 2024-10-20 19:32:45

Codeforces Round 273 Random Teams 解题心得的相关文章

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除

Codeforces Round #259 (Div. 2) 解题报告

终于重上DIV1了.... A:在正方形中输出一个菱形 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2014年08月01日 星期五 23时27分55秒 4 5 #include<vector> 6 #include<set> 7 #include<deque> 8 #include<stack> 9 #include<bitset> 10 #inclu

Codeforces Round #262 (Div. 2)解题报告

详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http://codeforces.com/contest/460/problem/A 有n双袜子,每天穿一双然后扔掉,每隔m天买一双新袜子,问最多少天后没有袜子穿.. 简单思维题:以前不注重这方面的训练,结果做了比较久,这种题自己边模拟边想.不过要多考虑trick ```c++ int main(){ i

Codeforces Round #616 (Div. 2)解题报告

Codeforces Round #616 (Div. 2)解题报告 A. Even But Not Even 找两个奇数就行了. #include<bits/stdc++.h> using namespace std; void solve() { int n; string s; cin >> n >> s; string ans = ""; for(int i = 0; i < n; i++) { if(int(s[i] - '0')%2

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 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 progra

Random Teams(Codeforces Round 273)

Description 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 th

Codeforces Round #273 (Div. 2) D. Red-Green Towers DP

链接: http://codeforces.com/problemset/problem/478/D 题意: 给出r个红砖,g个绿砖,问有多少种方法搭成最高的塔. 题解: 举红色球的层数,当第i层为红色是,i层上面有[0,r]个 红色的,可推出dp[i+j]=dp[i+j]+dp[j],最后 再统计红色的个数就行了,红色最少为max(h*(h+1)/2-g,0). 代码: 31 int dp[MAXN]; 32 33 int main() { 34 ios::sync_with_stdio(fa

codeforces Round #258(div2) C解题报告

C. Predict Outcome of the Game time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n games in a football tournament. Three teams are participating in it. Currently k games had alread

Codeforces Round #479 (Div. 3)解题报告

题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直接写,手速题,没啥好说的 B. Two-gram 题意 求出现次数最多的连续两个字符 还是签到题,我居然很麻烦地用了map,= =算了,思路畅通都无所谓了 #include <iostream> #include<stdio.h> #include<algorithm> #