URAL 2025. Line Fighting (math)
来源:互联网 发布:足球数据哪里有最全的 编辑:程序博客网 时间:2024/06/05 06:31
2025. Line Fighting
Time limit: 1.0 second
Memory limit: 64 MB
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:integersn and k separated with a space (2 ≤ k ≤ n ≤ 104).
Output
For each test output the answer (one integer) in a separate line.
Sample
36 35 54 2
12104Problem 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;}
0 0
- URAL 2025. Line Fighting (math)
- ural 2025. Line Fighting -思维题
- URAL 2025. Line Fighting 简单数学推理
- URAL - 2025 Line Fighting
- PROBLEM_B: URAL 2025 B - Line Fighting
- URAL 2025 Line Fighting 水题、贪心、均分
- timus 2025. Line Fighting
- URAL 1131. Copying (math)
- URAL 1796. Amusement Park (math)
- URAL 1019 Line Painting(解题报告)
- ural 1019 Line Painting (线段树)
- URAL 1019 - Line Painting(线段树)
- ural 1019 Line Painting
- ural 1019. Line Painting
- Ural 1019 Line Painting
- Ural 1019. Line Painting
- URAL 1019 - Line Painting
- Ural 1019. Line Painting
- wxWidgets之wxGrid控件
- How To Ask Questions The Smart Way -- 提问的智慧
- 怎样对用户数据进行保护
- 使用gcc的-E -P选项展开源代码中的宏
- 一个数组中有30个数(随机产生[0,30]),将数组中重复的数字去除,动态创建数组保存剩下的数字
- URAL 2025. Line Fighting (math)
- Codeforces Round #299 (Div. 2) A. Tavas and Nafas
- 循环和分支小应用--疯狂猜数字游戏
- 备战2015GRE之核心词组thus far
- MNIST Dataset
- ios 断点续传注意事项
- 如何利用PopupWindow实现弹出菜单并解决焦点获取以及与软键盘冲突问题
- AndroidManifest.xml文件属性详解
- 高中生如何攻克SAT词汇难关