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+ ...
随机推荐
- 2017-11-07-noip模拟题
T1 数学老师的报复 矩阵快速幂模板,类似于菲波那切数列的矩阵 [1,1]*[A,1 B,0] #include <cstdio> #define LL long long inline ...
- spring mvc 编写处理带参数的Controller
在上一随笔记录的基础上,现记录编写处理带有参数的Controller. @Controller //这个注解会告知<context:component:scan> 将HomeControl ...
- java布局(每个名字都是有意义的)
一.FlowLayout 1.流水布局:从左至右,排满换行 2.构造函数有三种: (1)FlowLayout() (2)FlowLayout(align) (3)FlowLayout(align, h ...
- 将可执行程序的内存空间扩展到3GB(windows)
为了告知操作系统这个应用程序可以支持/3GB方式,我们需要往exe 文件头中添加一个 IMAGE_FILE_LARGE_ADDRESS_AWARE 标志.添加的方式很简单: 在你的系统的 Progra ...
- windows pipe
管道分为 匿名管道 和 命名管道 . 1.匿名管道仅仅能在父子进程间进行通信.不能在网络间通信,并且传输数据是单向的.仅仅能一端写,还有一端读. 2.命令管道能够在随意进程间通信.通信是双向的,随意一 ...
- 利用Python自动发送邮件
# -*- coding:utf-8 -*-from email.mime.text import MIMETextfrom email.header import Headerimport smtp ...
- Unity3d载入外部图片文件
unity里的图片在生成时会压缩成资源文件,有时客户想自己放一些图片用unity显示,就必须载入外部图片. 大体思路:用Application.streamingAssetsPath或Applicat ...
- Odoo calendar 提醒器
Odoo calendar 提供了一个提醒功能,它包含邮件通知以及web client弹窗功能 创建日历事件的时候,可以设置提醒器 Meeting [ calendar.event ] ...
- 以goroutine为例看协程的相关概念
转自 http://wangzhezhe.github.io/blog/2016/02/17/golang-scheduler/ 基本上是网上相关文章的梳理,初衷主要是想了解下golang中的gor ...
- 树状数组求最大值 (RMQ with Shifts)
代码: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib ...