UVa - 10194 - Train Swapping

2024-06-05 11:48
文章标签 train uva swapping 10194

本文主要是介绍UVa - 10194 - Train Swapping,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦        怀着无比激动的心情。   某大神助攻。 不然就废了



收:strcasecmp(s1, s2); 



题目大意:

多支队伍比赛。 记录每支队伍

1总共赢的分数(赢了得3分,平得1分,输不得分)

2共比赛的场数

3共赢的常数

4共平的场数

5共输的场数

6赢球数与输球数之差

7共赢的球数(输的场中也要算,下同)

8共输球场数


然后排序输出,优先条件;

1赢分多

2赢场多

3赢球与输球只差大

4赢球多

5比赛场数少

6字典序


#include<iostream>
#include<stdio.h>
#include<set>
#include<queue>
#include<string.h>
#include<algorithm>using namespace std;struct Team
{char name[35];int tpe;int gp;int wins;int ties;int losses;int gd;int gs;int ga;
};Team team[35], t;	
int n, i, j, k, team1, game, score1, score2;
char c, str[110], str1[35], str2[35];int getNumber(char *s)
{for  (k = 0; k < team1; k ++)if (strcmp(s, team[k].name) == 0){return k;}
}bool cmp(Team a, Team b)
{if (a.tpe == b.tpe){if (a.wins == b.wins){if (a.gd == b.gd){if (a.gs == b.gs){if (a.gp == b.gp){if (strcasecmp(a.name, b.name) < 0)return true;else return false;}else return a.gp < b.gp;}elsereturn a.gs > b.gs;}else return a.gd > b.gd;}else return a.wins > b.wins;}elsereturn a.tpe > b.tpe;
}int main()
{scanf("%d%*c", &n);while (n --){memset(team, 0, sizeof(team));gets(str);scanf("%d%*c", &team1);for (i = 0; i < team1; i ++)gets(team[i].name);		scanf("%d%*c", &game);for (i = 0; i < game; i ++){j = 0;while (scanf("%c", &c) && c != '#'){str1[j ++] = c;}str1[j] = '\0';int k1;k1 = getNumber(str1);team[k1].gp ++;scanf("%d", &score1);getchar();scanf("%d", &score2);getchar();gets(str2);int k2;k2 = getNumber(str2);team[k2].gp ++;if (score1 > score2){team[k1].wins ++;team[k1].tpe += 3;team[k2].losses ++;}else if (score1 == score2){team[k1].ties ++;team[k1].tpe ++;team[k2].ties ++;team[k2].tpe ++;}else if (score1 < score2){team[k1].losses ++;team[k2].wins ++;team[k2].tpe += 3;}team[k1].gs += score1;team[k1].ga += score2;team[k2].gs += score2;team[k2].ga += score1;}for (i = 0; i < team1; i ++)team[i].gd = team[i].gs - team[i].ga;sort(team, team + team1, cmp);		puts(str);for (i = 0; i < team1; i ++){printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", i + 1, team[i].name, team[i].tpe, team[i].gp, team[i].wins, team[i].ties, team[i].losses, team[i].gd, team[i].gs, team[i].ga);	}if (n != 0)printf("\n");}return 0;
}


 Problem A: Football (aka Soccer) 

The Problem

Football the most popular sport in the world (americans insist to call it "Soccer", but we will call it "Football"). As everyone knows, Brasil is the country that have most World Cup titles (four of them: 1958, 1962, 1970 and 1994). As our national tournament have many teams (and even regional tournaments have many teams also) it's a very hard task to keep track of standings with so many teams and games played!

So, your task is quite simple: write a program that receives the tournament name, team names and games played and outputs the tournament standings so far.

A team wins a game if it scores more goals than its oponent. Obviously, a team loses a game if it scores less goals. When both teams score the same number of goals, we call it a tie. A team earns 3 points for each win, 1 point for each tie and 0 point for each loss.

Teams are ranked according to these rules (in this order):

  1. Most points earned.
  2. Most wins.
  3. Most goal difference (i.e. goals scored - goals against)
  4. Most goals scored.
  5. Less games played.
  6. Lexicographic order.

The Input

The first line of input will be an integer N in a line alone (0 < N < 1000). Then, will follow N tournament descriptions. Each one begins with the tournament name, on a single line. Tournament names can have any letter, digits, spaces etc. Tournament names will have length of at most 100. Then, in the next line, there will be a number T (1 < T <= 30), which stands for the number of teams participating on this tournament. Then will follow T lines, each one containing one team name. Team names may have any character that have ASCII code greater than or equal to 32 (space), except for '#' and '@' characters, which will never appear in team names. No team name will have more than 30 characters.

Following to team names, there will be a non-negative integer G on a single line which stands for the number of games already played on this tournament. G will be no greater than 1000. Then, G lines will follow with the results of games played. They will follow this format:

team_name_1#goals1@goals2#team_name_2
For instance, the following line:
Team A#3@1#Team B
Means that in a game between Team A and Team B, Team A scored 3 goals and Team B scored 1. All goals will be non-negative integers less than 20. You may assume that there will not be inexistent team names (i.e. all team names that appear on game results will have apperead on the team names section) and that no team will play against itself.

The Output

For each tournament, you must output the tournament name in a single line. In the next T lines you must output the standings, according to the rules above. Notice that should the tie-breaker be the lexographic order, it must be done case insenstive. The output format for each line is shown bellow:

[a]) Team_name [b]p, [c]g ([d]-[e]-[f]), [g]gd ([h]-[i])
Where:
  • [a] = team rank
  • [b] = total points earned
  • [c] = games played
  • [d] = wins
  • [e] = ties
  • [f] = losses
  • [g] = goal difference
  • [h] = goals scored
  • [i] = goals against
There must be a single blank space between fields and a single blank line between output sets. See the sample output for examples.

Sample Input

2
World Cup 1998 - Group A
4
Brazil
Norway
Morocco
Scotland
6
Brazil#2@1#Scotland
Norway#2@2#Morocco
Scotland#1@1#Norway
Brazil#3@0#Morocco
Morocco#3@0#Scotland
Brazil#1@2#Norway
Some strange tournament
5
Team A
Team B
Team C
Team D
Team E
5
Team A#1@1#Team B
Team A#2@2#Team C
Team A#0@0#Team D
Team E#2@1#Team C
Team E#1@2#Team D

Sample Output

World Cup 1998 - Group A
1) Brazil 6p, 3g (2-0-1), 3gd (6-3)
2) Norway 5p, 3g (1-2-0), 1gd (5-4) 
3) Morocco 4p, 3g (1-1-1), 0gd (5-5)
4) Scotland 1p, 3g (0-1-2), -4gd (2-6)Some strange tournament
1) Team D 4p, 2g (1-1-0), 1gd (2-1)
2) Team E 3p, 2g (1-0-1), 0gd (3-3)
3) Team A 3p, 3g (0-3-0), 0gd (3-3)
4) Team B 1p, 1g (0-1-0), 0gd (1-1)
5) Team C 1p, 2g (0-1-1), -1gd (3-4)




这篇关于UVa - 10194 - Train Swapping的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1032969

相关文章

UVA - 12206 Stammering Aliens (hash)

这题其实很容易想到2分长度,关键是2分后,怎么判断出现最多次的串是否》=m次了。这里需要用到hash来处理。 对于一个字符串   H[i] =H[i+1]*131+s[i]  ;其中 H[n]=0;那么对于一个长度为L的串 ,hanh[i,l]=H[i]-H[i+L]*x^L ; 这样记录每个字符串的hash值,然后再处理起来就比较简单了。 VIEW CODE #include<

【chatgpt】train_split_test的random_state

在使用train_test_split函数划分数据集时,random_state参数用于控制随机数生成器的种子,以确保划分结果的可重复性。这样,无论你运行多少次代码,只要使用相同的random_state值,得到的训练集和测试集划分就会是一样的。 使用 train_test_split 示例 以下是一个示例,展示如何使用train_test_split函数进行数据集划分,并设置random_s

tf.train.batch和tf.train.shuffle_batch的理解

capacity是队列的长度 min_after_dequeue是出队后,队列至少剩下min_after_dequeue个数据 假设现在有个test.tfrecord文件,里面按从小到大顺序存放整数0~100 1. tf.train.batch是按顺序读取数据,队列中的数据始终是一个有序的队列, 比如队列的capacity=20,开始队列内容为0,1,..,19=>读取10条记录后,队列剩下10,

[Uva 11990] Dynamic Inversion (CDQ分治入门)

Uva - 11990 动态逆序对,求删除一个点之前序列中逆序对的个数 首先倒过来看这个问题,把点先全部删掉 然后从最后一个点开始倒着往数列中加点 求加完这个点逆序对的变化 CDQ分治做法 把删除时间看作 t,下标看作 x,值看作 y 然后对 x排序,对 t偏序,用树状数组维护 y 具体来说就是对于每个点 (t0,x0,y0) (t_0, x_0, y_0) 先统计

ValueError: Shape must be rank 0 but is rank 1 for 'train_data/ReadFile' (op: 'ReadFile') with input

使用函数tf.train.slice_input_producer读取文件时, input_queue = tf.train.slice_input_producer([flist], shuffle=self.shuffle,seed=0123, num_epochs=self.num_epochs)input_file = tf.read_file(input_queue) 出现错误:

UVA 11624 搜索

给出1000*1000矩阵,含起点‘J’,路‘.',墙‘#’,火‘F'; 火每秒蔓延一格,人每秒走一步 问人是否可以安全走出矩阵,不能被火碰到 先对所有火BFS一遍,记录每个点被烧到的时间 然后对人BFS一遍,若到每点前没被火烧即可走 #include "stdio.h"#include "string.h"#include "queue"using namespace

UVa 11361 Investigating Div-Sum Property

这道题居然提交了十次才过....期间小问题不断。思路的话基本是《训练指南》里面来的,不过有几个小问题需要注意一下。第一,当K在大于100的情况下,就直接输出0就可以了。因为a,b不超过2^31,可以估算出a,b最多十位十进制数,那么每位最大为9,所以各个数字之和是不可能超过100的,那么个数字之和为模K为0的条件是永远不可能到达的。       还有一点是,当剩余数字d=0时,当且

UVa 1362(LA 3516) Exploring Pyramids

依旧是《训练指南》上的一道例题。思路大致相同,即设有一个序列S(i),S(i+1),S(i+2)...S(j),d[i,j]为所求的解。当S(i)==S(k),i<k<=j 时,说明在k回到根,那么S(i+1)...S(k-1)构成一棵独立的子树(当然也可能并不是子树)。那么d[i,j]就要加上d[i+1,k-1]*d[k,j],不断递增k,每遇到一个k,d[i,j]+=d[i

UVa 11174 Stand in a Line

依旧是《训练指南》上的一道例题。书上讲的比较抽象,下面就把解法具体一下。因为涉及到父子关系,因此自然而然可以将n个节点构造成一棵树,最后将形成一个森林。接下来将使用递归的手法。设f(i)是以节点i为树根的子树,节点i有儿子c1,c2,c3....cj共j棵子树。s[i]为树根为i的子树包含的节点数。如果分别先给各个子树内部排序,那么毫无疑问, 共有f(c1)*f(c2)*f(c3).

UVa 11375 Matches

大年夜的写代码果然状态非常之差...感觉特别困,连个高精度都折腾了我好久。还是刘汝佳《训练指南》里的一道例题,解题思路其实也差不多,但是想对书里面的内容再讲讲。其中d[i]是代表i个火柴棒恰好能构成的正整数数目(不包含整数0),然后有点类似于动态规划的做法,通过已知的d[]求出剩下的d[]。        不过仔细想来貌似有点问题。例如已知d[j],那么d[j+num[0]]+=d[