题目来源

一、题目

A big football championship will occur soon! n teams will compete in it, and each pair of teams will play exactly one game against each other.
There are two possible outcomes of a game:
the game may result in a tie, then both teams get 1 point;
one team might win in a game, then the winning team gets 3 points and the losing team gets 0 points.
The score of a team is the number of points it gained during all games that it played.
You are interested in a hypothetical situation when all teams get the same score at the end of the championship. A simple example of that situation is when all games result in ties, but you want to minimize the number of ties as well.
Your task is to describe a situation (choose the result of each game) so that all teams get the same score, and the number of ties is the minimum possible.

n只球队,每两队之间比赛一次,一共进行n * (n - 1) / 2次比赛。平局各加一分,赢加三分,输不加分。要使n只队伍比赛结束后得分全部相同,而且平局的数量尽可能少,输出每场比赛的情况。

二、输入

The first line contains one integer t (1≤t≤100) — the number of test cases.
Then the test cases follow. Each test case is described by one line containing one integer n (2≤n≤100) — the number of teams.

第一行测试样例数t
第二行队伍数量n

三、输出

For each test case, print n*(n−1)/2 integers describing the results of the games in the following order: the first integer should correspond to the match between team 1 and team 2, the second — between team 1 and team 3, then 1 and 4, …, 1 and n, 2 and 3, 2 and 4, …, 2 and n, and so on, until the game between the team n−1 and the team n.
The integer corresponding to the game between the team x and the team y should be 1 if x wins, −1 if y wins, or 0 if the game results in a tie.
All teams should get the same score, and the number of ties should be the minimum possible. If there are multiple optimal answers, print any of them. It can be shown that there always exists a way to make all teams have the same score.

对于每个样例,输出n*(n−1)/2个整数,依次表示1队与2队、3队、…、n队,2队与3队、4队、…、n队…n-1队与n队的比赛情况。
1表示赢 ,0表示平,-1表示输。

四、样例

input:

2
2
3

output:

0
1 -1 1

Note
In the first test case of the example, both teams get 1 point since the game between them is a tie.
In the second test case of the example, team 1 defeats team 2 (team 1 gets 3 points), team 1 loses to team 3 (team 3 gets 3 points), and team 2 wins against team 3 (team 2 gets 3 points).

五、思路 + 代码

数据很小,规律简单,模拟即可。

题目要求是每个人的分数一样,可以理解为每个人的胜负平一样,且胜场和负场一样多。

从1号到n号依次考虑。
对于第i个队伍,如果i是奇数,那么要求赢一半输一半,否则用平局来凑;如果i是偶数,那么要求这个队伍为其他队伍“配平”,使对手的胜场与负场一样。

这样一来会发现:每考虑完一个偶数号队伍,在场的所有队伍都满足各自的胜场 = 负场。那么假如最后一个考虑的队伍是奇数号,那么他的对手只有1个,平局即可;最后一个考虑的队伍是偶数号,配平后全场每个队伍胜场 = 负场。

代码如下:

#include<iostream>
using namespace std;
int n;
int sta[105][105];
int sc[105];
void solve() {cin >> n;//当前选手for (int i = 1; i <= n; i++) {//奇数个对手需要平局int needtie = (n - i) & 1;int tot = (n - i) / 2;int f = 0;int cnt = 0;//奇数选手不考虑对手得分if (i & 1) {for (int j = i + 1; j <= n; j++) {if (needtie) {sta[i][j] = 0;needtie = 0;continue;}//赢一半if (f == 0) {sta[i][j] = 1;sc[i]++;sc[j]--;cnt++;if (cnt == tot) f = 1;continue;}//输一半if (f == 1) {sta[i][j] = -1;sc[i]--;sc[j]++;cnt++;}}}//偶数选手负责配平else {for (int j = i + 1; j <= n; j++) {if (sc[j] > 0) {sta[i][j] = 1;sc[j]--;sc[i]++;}else if (sc[j] < 0) {sta[i][j] = -1;sc[j]++;sc[i]--;}}}}for (int i = 1; i <= n; i++) {for (int j = i + 1; j <= n; j++) {cout << sta[i][j] << " ";}}cout << endl;
}
int main() {int t;cin >> t;while (t--) {solve();}return 0;
}

C. Minimum Ties相关推荐

  1. Educational Codeforces Round 104 (Rated for Div. 2)A~E解题报告

    Educational Codeforces Round 104 (Rated for Div. 2) A. Arena \quad原题链接 http://codeforces.com/contest ...

  2. Educational Codeforces Round 104 (Rated for Div. 2) A,B,C,D,E

    Educational Codeforces Round 104 (Rated for Div. 2) A,B,C,D,E A - Arena 题意 nnn 个英雄,他们的等级分别是 a1,a2,-, ...

  3. Educational Codeforces Round 104 (Rated for Div. 2)

    A. Arena 题目传送门: A. Arena 题目大意: 有n个人,每个人都有战斗力,当两个人打起来时,战斗力高的人赢并且战斗力加1,当战斗力达到100500时,则成为英雄.问能有多少人能成为英雄 ...

  4. Error:This Gradle plugin requires Studio 3.0 minimum

    导入一个demo提示Error:This Gradle plugin requires Studio 3.0 minimum 在gradle.properties中导入 android.injecte ...

  5. Error:The SDK Build Tools revision (23.0.3) is too low for project ':app'. Minimum required is 25.0.

    导入github上项目的时候出现 Error:The SDK Build Tools revision (23.0.3) is too low for project ':app'. Minimum ...

  6. [leetcode] Minimum Path Sum

    Minimum Path Sum Given a m x n grid filled with non-negative numbers, find a path from top left to b ...

  7. 【C++】C++11 STL算法(六):最小/最大操作(Minimum/maximum operations)、比较运算(Comparison operations)

    目录 最小/最大操作(Minimum/maximum operations) 一.max 1.原型: 2.说明: 3.官方demo 二.max_element 1.原型: 2.说明: 3.官方demo ...

  8. LeetCode 76. Minimum Window Substring / 567. Permutation in String

    76. Minimum Window Substring 典型Sliding Window的问题,维护一个区间,当区间满足要求则进行比较选择较小的字串,重新修改start位置. 思路虽然不难,但是如何 ...

  9. pandas使用max函数和min函数计算dataframe日期(时间)数据列中最大日期和最小日期对应的数据行(maximum and minimum date or time row)

    pandas使用max函数和min函数计算dataframe日期(时间)数据列中最大日期和最小日期对应的数据行(maximum and minimum date or time row in data ...

  10. pandas计算滑动窗口中的最小值实战(Rolling Minimum in a Pandas Column):计算单数据列滑动窗口中的最小值、计算多数据列滑动窗口中的最小值

    pandas计算滑动窗口中的最小值实战(Rolling Minimum in a Pandas Column):计算单数据列滑动窗口中的最小值.计算多数据列滑动窗口中的最小值 目录

最新文章

  1. python yield 和 return 对比分析
  2. Alfred+AppleScript实现快速复制当前文件夹路径
  3. 在tomcat中使用context节点部署工程
  4. 简单说明c语言中常用的基本数据类型有哪些,C语言基本数据类型的.ppt
  5. 20应用统计考研复试要点(part19)--概率论与数理统计
  6. C# XML字符串与DataTable相互转换
  7. SwarmKit知多少——来自源码世界的深入解读
  8. 马化腾:腾讯的梦想是“三张网”
  9. python的追加_Python追加添加相同的数据
  10. “SecureCRT遇到一个致命的错误且必须关闭”处理办法
  11. oracle10g--使用expdp导出数据和impdp导入数据
  12. ios模拟器 安装ipa_安装ipa到模拟器
  13. 英伟达显卡虚拟化vGPU实践指南
  14. Java使用comms-net jar包完成ftp文件上传进度的检测功能
  15. 详解MATLAB之MAX函数
  16. iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)
  17. TangIDE游戏开发之70行代码实现打地鼠
  18. 天梯赛座位 分配分数 20作者 陈越单位 浙江大学
  19. 批量下载xx艺术照片的简单爬虫
  20. 具名元组namedtuple

热门文章

  1. 苹果x屏幕失灵乱跳_苹果手机屏幕失灵怎么办?成都苹果维修点教你轻松处理!...
  2. CVE-2022-28512 Fantastic Blog CMS 1.0 版本存在SQL注入漏洞
  3. 分布式系统——MapReduce:Simplified Data Processing on Large Clusters论文
  4. 浅谈无线AP、无线路由器
  5. 镜头光晕是如何形成的?
  6. 计算机软件需要加书名号吗,软件著作权名称需要加书名号吗-举例说明一个软件的名称放在句子里应不应该用书名号,为什么?...
  7. 三次曲线和五次曲线函数
  8. C语言发展史——程序猿抗争史
  9. Accton Technology and Wedge Networks Partnership Launches Orchestrated Secure SD-WAN
  10. Failure [INSTALL_FAILED_INVALID_APK]