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. 文件MD5

    package mainimport (    "crypto/md5"    "fmt"    // "github.com/astaxie/bee ...

  2. 【刷题 Python Tip】题目6~10

    [题目6]输出100以内的所有素数,素数之间以一个空格区分 from math import sqrt print ' '.join(str(key) for key in [x for x in x ...

  3. “玲珑杯”郑州轻工业学院第八届ACM程序设计大赛暨河南高校邀请赛-正式赛(总结)

    这次轻院校赛,我们去了五个队,怀着打酱油的心态早早爬起来坐上校车出发了,由于昨晚室友打游戏,以及看视频大笑...没睡好,快1点才睡着,感觉特别困,车上没地方,睡不着,就在车上闭目养神,由于在新校区,不 ...

  4. 【DataStructure】Some useful methods about linkedList(二)

    Method 1: Add one list into the other list. For example, if list1is {22, 33, 44, 55} and  list2 is { ...

  5. Html、CSS、JavaScript 实时效果在线编辑器 - 学习的好工具,算不算?!

    关于 二维码 与 NFC 之间的出身贫贱说 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 ...

  6. unity tips

    1.在unity 的mecanim中,如果一个动画指向两个或两个以上的动画,那么在inspector中,transitions中可以看到所有的过渡路径,这些路径是有先后顺序的.

  7. error: ‘for’ loop initial declarations are only allowed in

    使用gcc,出现如下错误: thread_join.c:7:5: error: 'for' loop initial declarations are only allowed in C99 mode ...

  8. FtpClient的使用

    摘自:http://hi.baidu.com/yuanhotel/item/000b6334894d11f42784f4da Java的ftp操作 package com.why.ftp; impor ...

  9. WinForm设置控件焦点(转)

    http://blog.csdn.net/zlwzlwzlw/article/details/8573921 winform窗口打开后文本框的默认焦点设置,进入窗口后默认聚焦到某个文本框,两种方法: ...

  10. Unicode-字符编码的历史由来(转)

    http://www.nowamagic.net/internet/internet_CharsetHistory.php 很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以 ...