URAL 2025. Line Fighting (math)

Source: Internet
Author: User

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≤ kN≤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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.