codeforces Codeforces Round #273 (Div. 2) 478B
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.
算法分析:1. n-1 个队有一个人,其余人都放到地n队,这样组合出来最多。
2. 将n个人尽量均分到每个队,这样获得组合最少。
3. m==1 和 m==n的情况进行一下剪枝。
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm> using namespace std; int main()
{
long long n, m;
long long dd, ff, gg, d;
long long mi, ma; while(scanf("%lld %lld", &n, &m)!=EOF) //鉴于此处为什么用long long,我也不清楚,就因为这两处的数据类型,我WA了8遍。
{
if(m==1)
{
dd=n*(n-1)/2;
printf("%lld %lld\n", dd, dd);
continue;
}
if(n==m)
{
printf("0 0\n");
continue;
}
dd=n-(m-1);
ma=dd*(dd-1)/2; ff=n/m;
gg=n%m;
d=n-ff*m; mi=ff*(ff-1)/2*(m-d);
mi=mi+ff*(ff+1)/2*d; if(mi>ma)
{
mi=mi^ma; ma=ma^mi; mi=mi^ma;
}
printf("%lld %lld\n", mi, ma );
}
return 0;
}
codeforces Codeforces Round #273 (Div. 2) 478B的更多相关文章
- 贪心 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 Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
随机推荐
- Android 防护扫盲篇
一,已知防护策略 1.不可或缺的混淆 Java 是一种跨平台.解释型语言,Java 源代码编译成的class文件中有大量包含语义的变量名.方法名的信息,很容易被反编译为Java 源代码.为了防止这种现 ...
- numpy常用函数学习
目录numpy常用函数学习点乘法线型预测线性拟合裁剪.压缩和累乘相关性多项式拟合提取符号数组杂项点乘法该方法为数学方法,但是在numpy使用的时候略坑.numpy的点乘为a.dot(b)或numpy. ...
- EasyMvc入门教程-基本控件说明(9)引言导航
休息片刻后,继续开工... 这次我们继续学习引言导航,引言导航主要用于知识点的开始,起到知识点导航的作用.直接例子: 实现代码如下: @Html.Q().BlockRef().Title(" ...
- 客户端svn出现authorization failed异常
原文:https://blog.csdn.net/big1989wmf/article/details/70144470 发现,原来是 服务端上面 svnserve 这个进程没有启动起来 然后,再试一 ...
- display:flex不兼容Android、Safari低版本的解决方案 【flex布局】
引自 http://www.cnblogs.com/shimily/articles/7943370.html <!DOCTYPE html> <html lang="en ...
- iOS加急审核之2015年总结
就在今天到公司的一会,查看了一下邮件,收到Apple的回复,今年的第六次加急审核通过了. 然后,想想明天就是西方的圣诞节假期了,从22日到29日的这段时间,Apple会暂时关闭iTunesconnec ...
- hdu杭电1856 More is better【并查集】
Problem Description Mr Wang wants some boys to help him with a project. Because the project is rathe ...
- PS 基础知识 CMYK全称是什么
已解决 请问谁知道CMYK四色的英文全称? 悬赏分:20 - 解决时间:2006-9-6 16:23 C代表什么颜色?英文全称是什么? M代表什么颜色?英文全称是什么? Y代表什么颜色?英文全称是什么 ...
- 数据结构与算法系列----AC自己主动机
一:概念 首先简要介绍一下AC自己主动机:Aho-Corasick automation,该算法在1975年产生于贝尔实验室,是著名的多模匹配算法之中的一个.一个常见的样例就是给出n个单词,再给出一段 ...
- 使用fuser命令kill一个终端(特殊文件)的方法
/********************************************************************* * Author : Samson * Date ...