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 ≤ kn ≤ 104).

Output

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

Sample

input output
3
6 3
5 5
4 2
12
10
4

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)的更多相关文章

  1. 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 ...

  2. 组合数学(math)

    组合数学(math) 题目描述 为了提高智商,zjy开始学习组合数学.某一天她解决了这样一个问题:“给一个网格图,其中某些格子有财宝.每次从左上角出发,只能往右或下走.问至少要走几次才能把财宝全部捡完 ...

  3. URAL 1069 Prufer Code(模拟)

    Prufer Code Time limit: 0.25 secondMemory limit: 8 MB A tree (i.e. a connected graph without cycles) ...

  4. URAL 1741 Communication Fiend(最短路径)

    Description Kolya has returned from a summer camp and now he's a real communication fiend. He spends ...

  5. URAL 1139 City Blocks(数论)

    The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets ...

  6. Linux Command Line 笔记(1)

    Yunduan CUI graphical user interfaces make easy tasks easy, while command line interfaces make diffi ...

  7. URAL 1146 Maximum Sum(DP)

    Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the large ...

  8. ural 1100. Final Standings(数据结构)

    1100. Final Standings Time limit: 1.0 secondMemory limit: 16 MB Old contest software uses bubble sor ...

  9. ural 1146. Maximum Sum(动态规划)

    1146. Maximum Sum Time limit: 1.0 second Memory limit: 64 MB Given a 2-dimensional array of positive ...

随机推荐

  1. JNI的替代者—使用JNA访问Java外部功能接口

    摘自:http://www.cnblogs.com/lanxuezaipiao/p/3635556.html JNI的替代者-使用JNA访问Java外部功能接口 1. JNA简单介绍 先说JNI(Ja ...

  2. MySql 取一天的开始时间和结束时间

    -- 取一开的开始时间 SELECT str_to_date(DATE_FORMAT(NOW(),'%Y-%m-%d'),'%Y-%m-%d %H:%i:%s'); -- 取第二天的开始时间 sele ...

  3. python2 和3的区别

    __future__ 模块 Python 3.x引入一些Python2不兼容的关键字和函数,可以通过在 Python2 内置的模块 __future__ 导入.建议如果你想在代码中支持 Python3 ...

  4. 格而知之7:我所理解的Runtime(2)

    消息发送(Messaging) 8.以上便是runtime相关的一些数据结构,接下来我们回看一开始的疑问: objc_msgSend()函数在执行的过程中是如何找到对应的类,找到对应的方法实现的呢? ...

  5. IT人士的职业规范——凝视

     这两天将系统敲完了,该总体调试了,调试的过程中,发现了一个非常大的问题,就是自己的凝视写的不够,有时候不明确U层这个事件是做什么的,有时候不知道这个事件传递的是什么參数,有时候不知道相应的B层和 ...

  6. Javascript中闭包的作用域链

    作用域定义了在当前上下文中能够被访问到的成员,在Javascript中分为全局作用域和函数作用域,通过函数嵌套可以实现嵌套作用域. 闭包一般发生在嵌套作用域中.闭包是JavaScript最强大的特性之 ...

  7. TS相关知识点

    数字电视的TS包和TS流的组成和功能 综合考虑几下几个因素: (1)包的长度不能过短,否则包头开销所占比例过大, 导致传输效率下降 (2)包的长度不能过长,否则在丢失同步的情况下恢复同步的 周期过长, ...

  8. ADO.net基础学习总结(二)

    将连接字符串放入配置文件中 1.添加一个“应用程序配置文件:app.config” <?xml version="1.0" encoding="utf-8" ...

  9. SQL Server 两种判断表名是否存在且删除的方式

      邓老师(老邓)教的 if exists(select * from sysobjects where name='Table_88') drop table Table_88  偷的((*^__^ ...

  10. JavaScript sort()方法比较器

    当我们想把一个由数字组成的数组进行简单的排序时,可能会想到sort()方法: var arr = [2 , 3, -1, -107, -14, 1]; console.log(arr.sort()) ...