UVA1418-WonderTeam (reasoning + greedy)

Source: Internet
Author: User

Question Link


Question: There are n teams playing each game. Each of the two teams plays two games (one for home and away). The game wins three points, and the score is equal to one point. After the competition, a dream team will be selected to meet the following conditions: the total number of goals is the maximum (not the same as that of the team), the maximum number of victories (not the same as that of the team), and the minimum number of missed goals (not the same as that of the team ). Find the lowest possible ranking of the dream team. The ranking of a team with a score of P is equal to the number of teams with an equal score strictly greater than P plus 1.

Train of Thought: in fact, the three conditions are the most useful only for the number of victories, because the Dream Team can win the game with a big score, the loss of the game is 0-1 to lose the opponent, the other two do not matter. To keep the Dream Team as low as possible, it means to keep the score as low as possible. We assume that the number of victories for the mengzhi team is 2, and the number of victories for other teams is 1. This satisfies the above conditions and minimizes the score of the mengzhi team.
When the number of participating teams is N:
Dream Team: Win 2 games, negative n-1, flat n-3 = 2*3 + n-3 = 3 + n
Among them 2 teams: Win 1 game, play 1 game, Flat 2 * n-4 = 1*3 + 2 * n-4 = 2 * n-1
Remaining Team (when n> 3 remaining team): Win 1 game, 0 game, 2 * n-3 = 2 * n
Therefore, the ranking can be obtained based on the score.

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main() {    int n;     while (scanf("%d", &n) && n) {        if (n <= 3)            printf("1\n");        else if (n == 4)            printf("2\n");        else            printf("%d\n", n);    }    return 0;}


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.