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+ ...
随机推荐
- Flink起步安装和使用
下载安装 下载地址 下载对应操作系统和版本的flink # 首先确认下Java环境 $ java -version java version "1.8.0_111" Java( ...
- kafka技术分享02--------kafka入门
kafka技术分享02--------kafka入门 1. 消息系统 所谓的Messaging System就是一组规范,企业利用这组规范在不同的系统之间传递语义准确对的消息,实现松耦合的异步数据 ...
- 数据结构------------------二叉查找树(BST)的java实现
数据结构------------------二叉查找树(BST)的java实现 二叉查找树(BST)是一种能够将链表插入的灵活性和有序数组查找的高效性相结合的一种数据结构.它的定义如下: 二叉查找树是 ...
- [__NSCFConstantString size]: unrecognized selector sent to instance 错误
因为使用时候的类型和初始化的对象类型不匹配造成的,例如 - (NSMutableDictionary *)getMenuItems{ NSArray *defaultTmp = [NSArray ...
- python 常见细节知识点
1. a[::-1]翻转 设有一个元组或者列表 a = (1,2,3,4) b = [1,2,3,4] 则a[::-1]和b[::-1]的含义是将元组或列表的内容翻转 a[::-1] # 结果为(4, ...
- spring secrity 一些常用小知识
1.在JSP页面获取当前登录的用户名的方法 首先引入taglib:<%@ taglib prefix="sec" uri="http://www.springfra ...
- linux下的环境文件设置说明
工作环境设置文件 环境设置文件有两种:系统环境设置文件 和 个人环境设置文件 1.系统中的用户工作环境设置文件: 登录环境设置文件:/etc/profile 非登录环境设置文件: ...
- Cocos2d-X中的粒子
Cocos2d-x引擎提供了强大的type=cocos2d-x&url=/doc/cocos-docs-master/manual/framework/native/v3/particle-s ...
- 抽象类的子类能够new
纠结了半天,我以为继承了Activity后不能new这里被那个onCreate方法迷惑了以为会出现故障一直没直接创建对象类使用 后来试了试才知道 activity似乎是一个抽象类吧. 你要用他的方法, ...
- win7-64bit下基于VMware12.5安装rhel-server-6.3-i386
/************************************************************************************* 宿主PC:win7-64b ...