2025. Line Fighting
Time limit:1.0 Second
Memory limit:64 MB
Boxing, karate, sambo ... The audience is sick of the classic combat sports. That's why a popular sports channel launches a new competition format based on the traditional Russian entertainment call Ed line fighting. There can is from 2 to
kTeams taking part in a competition, and there is
NFighters altogether in all the teams. Before the competition starts, the fighters is divided into Teams:each fighter becomes a member of exactly one team. The fighters fight each of the other if they is members of the different teams. The organizers believe the more the number of fights between fighters, the higher the popularity of a competition wil L be. Help the organizers-distribute fighters between teams so as to maximize the number of fights and output this number. Inputthe First line contains the number of tests
T(1≤
T≤10). In the following
TLines you given a test:integers
Nand
kSeparated with a space (2≤
k≤
N≤104). Outputfor each test output of 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
Analytic: Combinatorial mathematics. Because the group can not play the game, this is equivalent to all the people can play on the basis of the elimination of the number of games can be played between each group.
First of all, the most frequently played situation is certainly to divide the number of people as much as possible, this is the largest number of games.
AC Code:
#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; The number of matches between all people 22 if (n! = k) { int foo = n/k; int cnt = n% K; After averaging the remaining CNT individuals, then evenly divided. The group ans-= cnt * ((foo + 1) * FOO/2) will appear with a number of CNT numbers of more than 1; Remove the total number of CNT groups ans- = (k-cnt) * (foo * (foo-1)/2); Remove the total number of fewer people } printf ("%d\n", ans); } return 0;}
URAL 2025. Line Fighting (math)