URAL 2025. Line Fighting 简单数学推理

  2025. Line Fighting

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 ≤ 104).
Output
For each test output the answer (one integer) in a separate line.
Sample

input

3
6 3
5 5
4 2

output


12
10
4

Problem Author: Alexey Danilyuk
Problem Source: Ural Regional School Programming Contest 2014
Tags: none (hide tags for unsolved problems)

tho: 对于一种情况的方案解决策略如下
最终结果:

1.如果人数可以平均分到每只队伍中,则
ans=(一只队伍的人数×剩下的所有的人数×队伍总数)/2。【除2原因是高中知识点】
即从一个队中选出一人比赛有 这支队伍的人数 这么多种选择的可能性,而他又可以和其余队伍中任何选手比赛 所以
2.若不能均分,则要尽量平均分配
    举个栗子: 8 5
    (12) (34) (56)    (7)   (8)
这样分得到可以举办的比赛数目最多
此时 n/k = 1          n%k = 3
现在答案的计算可以分为两部分
①这部分是人少的队伍计算出的答案
 [(n/k) × (n- n/k) × (k - n%k)] / 2
 队中1人    剩余7人     这种队伍有(5-3)两只
②这部分是人多的队伍计算出的答案
 [(n/k + 1) × (n- n/k -1) × (n%k)] / 2
 队中2人    剩余6人     这种队伍有3只
**因为总数除以二了所以不会出现重复的**

推演后发现,第二种情况导出的式子包含第一种情况。

code:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        LL n,k;
        scanf("%lld%lld",&n,&k);
        LL chu = n/k;
        LL mo = n%k;
        LL lesss = chu*(n-chu)*(k-mo);
        LL moree = (chu+1)*(n-chu-1)*mo;
        printf("%lld\n",(lesss+moree)/2);
    }
    return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值