博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
URAL 2025. Line Fighting (math)
阅读量:7059 次
发布时间:2019-06-28

本文共 1841 字,大约阅读时间需要 6 分钟。

Time limit: 1.0 second
Memory limit: 64 MB
Boxing, karate, sambo… The audience is sick of classic combat sports. That is why a popular sports channel launches a new competition format based on the traditional Russian entertainment called line fighting.There can be from 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

The first line contains the number of tests
T (1 ≤
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 ≤ 10
4).

Output

For each test output the answer (one integer) in a separate line.

Sample

input output
36 35 54 2
12104
Problem Author: Alexey Danilyuk
Problem Source: Ural Regional School Programming Contest 2014

解析:组合数学。因为组内不能打比赛,这就相当于在全部人都能比赛的基础上去掉了各个组间能打的比赛次数。

首先,比赛次数最多的情况肯定是尽可能地将人数均分,这种比赛数是最多的。

AC代码:

#include 
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;}

转载地址:http://zlrol.baihongyu.com/

你可能感兴趣的文章
ThinkPHP配置简单的mysql读写分离
查看>>
AngularJS Select(选择框)
查看>>
EXT.NET入门必读
查看>>
数据结构定义
查看>>
实验报告二201521460014
查看>>
微服务Kong(八)——代理参考
查看>>
jQuery easyui layout布局自适应浏览器大小
查看>>
C++中accumulate的用法
查看>>
sql中的Replace
查看>>
POJ 1068 AC 2014-01-07 15:24 146人阅读 评论(0) 收藏...
查看>>
A. Karen and Morning
查看>>
虚拟内存和虚拟地址空间理解(转载)
查看>>
[LeetCode] Pow(x, n) 二分搜索
查看>>
简记mysql中文乱码(插入变成??)的问题.
查看>>
C# 科学计数法转换成数字
查看>>
深入理解:java类加载器
查看>>
Android Studio使用Git版本控制github
查看>>
跳转到移动终端
查看>>
【转载】C# sleep 和wait的区别
查看>>
Linux实现删除撤回的方法。
查看>>