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. Since it is not possible to play in a group, it is tantamount to removing the number of games that can be played between groups, based on the ability of everyone to play.
First of all, the most frequently played situations are definitely to divide the number of people as much as possible, so that the number of matches is the most.
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 games played between all 22 if (n! = k) { int foo = n/k; int cnt = n% K; After evenly dividing the remaining CNT individuals, then evenly, there will be a group of CNT more than 1 ans-= cnt * ((foo + 1) * FOO/2); 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)