CF478 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 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.
虽然是道水题,但是我还是想说下。
题意:已知∑ai=n(i从1到m),求∑C(2,ai)的最大值和最小值
要求ai>=1
化简:原式=(∑(ai^2)-n)/2
所以只要求出∑(ai^2)的最值即可
考虑我们分配2个数x,y,根据贪心:
x^2+y^2<=(x-1)^2+(y+1)^2 (x<y)
所以要让平方和更大,我们应该从x中拿更多的给y,最终就是x=1,y尽量大
y再和其他数比较,也是同样的结果,最终,我们得到:
当m-1个为1,1个为n-m+1的时候,得到最大值
同理,当m个数尽量平均的时候,就得到最小值。
#include<cstdio>
#include<iostream> #define LL long long using namespace std; int main()
{
LL n,m;
cin>>n>>m;
LL tmax=,tmin=;
tmax=m-+(n-m+)*(n-m+);
LL a=n/m;
LL b=n%m;
int i=;
tmin=b*(a+)*(a+)+(m-b)*(a*a); cout<<(tmin-n)/<<" "<<(tmax-n)/<<endl;
return ;
}
CF478 B. Random Teams 组合数学 简单题的更多相关文章
- 【CODEFORCES】 B. Random Teams
B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- BZOJ 2683: 简单题
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 913 Solved: 379[Submit][Status][Discuss] ...
- 【BZOJ-1176&2683】Mokia&简单题 CDQ分治
1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 1854 Solved: 821[Submit][St ...
- Bzoj4066 简单题
Time Limit: 50 Sec Memory Limit: 20 MBSubmit: 2185 Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...
- Bzoj2683 简单题
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 1071 Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...
- 这样leetcode简单题都更完了
这样leetcode简单题都更完了,作为水题王的我开始要更新leetcode中等题和难题了,有些挖了很久的坑也将在在这个阶段一一揭晓,接下来的算法性更强,我就要开始分专题更新题目,而不是再以我的A题顺 ...
- [BZOJ2683][BZOJ4066]简单题
[BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...
- HDU 1753 大明A+B(字符串模拟,简单题)
简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...
- 团体程序设计天梯赛-练习集L1-014. 简单题
L1-014. 简单题 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 这次真的没骗你 —— 这道超级简单的题目没有任何输入. ...
随机推荐
- 穿越泥地(mud) (BFS)
问题 C: 穿越泥地(mud) 时间限制: 1 Sec 内存限制: 128 MB提交: 16 解决: 10[提交][状态][讨论版] 题目描述 清早6:00,FJ就离开了他的屋子,开始了他的例行工 ...
- Kali linux渗透测试的艺术 思维导图
Kali Linux是一个全面的渗透测试平台,其自带的高级工具可以用来识别.检测和利用目标网络中未被发现的漏洞.借助于Kali Linux,你可以根据已定义的业务目标和预定的测试计划,应用合适的测试方 ...
- Linux驱动设计—— 内核模块(一)
Linux内核理论基础 组成Linux内核的5个子系统:进程调度(SCHED)/内存管理(MM)/虚拟文件系统(VFS)/网络接口(NET)/进程间通信(IPC). 进程调度(SCHED) 在设备驱动 ...
- android开源项目---tool篇
本文转载于:http://blog.csdn.net/likebamboo/article/details/19080801 主要包括那些不错的开发库,包括依赖注入框架.图片缓存.网络相关.数据库OR ...
- UMDH
1. 什么是UMDH UMDH=User Mode dump heap.把进程的堆dump下来.包括堆栈信息.UMDH是WinDbg附带的一个工具. 2. 下载安装 WinDbg.完事后在WinDbg ...
- python部分模块的安装
scrapy http://www.cnblogs.com/txw1958/archive/2012/07/12/scrapy_installation_introduce.html pyHook - ...
- SQL注入脚本(基于时间)
#encoding=utf-8 import httplib import time import string import sys import urllib header = {'Accept' ...
- ejs使用
ejs使用 从npm上下载最新的ejs刚写了个例子 先pull出来,网上太多例子都不好用,googlecode上的代码根本下不下来,只能去翻npm安装下来的文件里的说明文件,模仿着写出来一个 var ...
- 现在流行什么 JS库/框架?
现在大家最感兴趣的 JS 库和框架是什么? jQuery 91.5% Underscore 38.6% AngularJS 28.5% Backbone 18.6% React 15.7% Knock ...
- JdbcUtils
JdbcUtils 项目结构 db.properties driverClass=com.mysql.jdbc.Driver url=jdbc:mysql:///myTest username=r ...