URAL 2025. Line Fighting (math)
2025. Line Fighting
Memory limit: 64 MB
2 to k teams taking part in a competition, and there are n fighters altogether in all the teams. Before the competition starts, the fighters are divided into teams: each fighter becomes a member of exactly one team.Two fighters fight each
other if they are members of different teams. The organizers believe that the more the number of fights between fighters, the higher the popularity of a competition will be. Help the organizers to distribute fighters between teams so as to maximize the number
of fights and output this number.
Input
T ≤ 10). In each of the following T lines you are given a test:integers
n and k separated with a space (2 ≤ k ≤ n ≤ 104).
Output
Sample
input | output |
---|---|
3 |
12 |
Problem Author: Alexey Danilyuk
Problem Source: Ural Regional School Programming Contest 2014
解析:组合数学。因为组内不能打比赛,这就相当于在全部人都能比赛的基础上去掉了各个组间能打的比赛次数。
首先,比赛次数最多的情况肯定是尽可能地将人数均分,这种比赛数是最多的。
AC代码:
#include <bits/stdc++.h>
using namespace std; int main(){
#ifdef sxk
freopen("in.txt", "r", stdin);
#endif // sxk int T, n, k, ans;
scanf("%d", &T);
while(T --){
scanf("%d%d", &n, &k);
ans = n * (n - 1) / 2; //全部人两两之间打比赛的次数
if(n != k){
int foo = n / k;
int cnt = n % k; //均分后剩余cnt个人,再均分。则会出现cnt个人数多1的组
ans -= cnt * ((foo + 1) * foo / 2); //去掉人数较多的cnt组的总次数
ans -= (k - cnt) * (foo * (foo - 1) / 2); //去掉人数较少的总次数
}
printf("%d\n", ans);
}
return 0;
}
URAL 2025. Line Fighting (math)的更多相关文章
- URAL 1796. Amusement Park (math)
1796. Amusement Park Time limit: 1.0 second Memory limit: 64 MB On a sunny Sunday, a group of childr ...
- 组合数学(math)
组合数学(math) 题目描述 为了提高智商,zjy开始学习组合数学.某一天她解决了这样一个问题:“给一个网格图,其中某些格子有财宝.每次从左上角出发,只能往右或下走.问至少要走几次才能把财宝全部捡完 ...
- URAL 1069 Prufer Code(模拟)
Prufer Code Time limit: 0.25 secondMemory limit: 8 MB A tree (i.e. a connected graph without cycles) ...
- URAL 1741 Communication Fiend(最短路径)
Description Kolya has returned from a summer camp and now he's a real communication fiend. He spends ...
- URAL 1139 City Blocks(数论)
The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets ...
- Linux Command Line 笔记(1)
Yunduan CUI graphical user interfaces make easy tasks easy, while command line interfaces make diffi ...
- URAL 1146 Maximum Sum(DP)
Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the large ...
- ural 1100. Final Standings(数据结构)
1100. Final Standings Time limit: 1.0 secondMemory limit: 16 MB Old contest software uses bubble sor ...
- ural 1146. Maximum Sum(动态规划)
1146. Maximum Sum Time limit: 1.0 second Memory limit: 64 MB Given a 2-dimensional array of positive ...
随机推荐
- NSNotificationCenter 传对象
[[NSNotificationCenter defaultCenter] postNotificationName:@"postCity" object:pro]; [[NSNo ...
- SQL SERVER 2005 错误:18456
安装好SQL SERVER 2005之后,Windows身份验证无法登陆,出现18456错误.而sql server 身份验证可以用sa用户登陆. 解决办法: 用sa用户登陆,执行SQL 语句: CR ...
- eclipse安装svn插件,在输入url后,一直卡在in progress界面不懂。
今天遇到上面的情况.网上找了半天都没有找到解决的办法.后来,仔细比对了一下我的eclipse版本和svn版本.发现svn版本真的太老了.用上新的svn后,立马就可以用了 svn - http://su ...
- 改变页面选择文字颜色和背景颜色----selection伪元素
div::selection{color:#fff;background: #E83E84;text-shadow:none}
- 定时排程刷新微信access-token
微信公众号开发中最常遇到的就是调用接口时候需要有API的access-token(非网页授权的access-token),有了这个token之后,才可以发生模板消息等.这里的做法主要是用nodejs的 ...
- div背景等比例缩小
background: url("http://www.asdear.com/Content/loginPage/newimages/nchina.png") 50% 0px no ...
- ASP.NET MVC学习之路由篇
约束路由 上面我们有一个{id}用来捕获参数的,但是你也发现了它可以捕捉任何字符串等等,但是我们有时需要限制它,比如让它只能输入数字,那么我们就可以使用正则表达式去约束它. 如下修改RouteConf ...
- C# sliverlight调用WCF服务出现的一个错误
错误提示如下: 尝试向 URI“http://localhost:8396/Service1.svc”发出请求时出错.这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP ...
- 从汇编看c++多重继承中this指针的变化
先来看一下下面的c++源码: #include <iostream> using namespace std; class X { public: virtual void print1( ...
- Repeater实现数据绑定
Repeater基础 在aspx文件中加入Repeater 控件,在<ItemTemplate></ItemTemplate>包含的范围里加入自己控制的代码,需要替换的变量使用 ...