首页 > 其他分享 >CodeForces - 234E Champions' League(模拟)

CodeForces - 234E Champions' League(模拟)

时间:2023-02-04 11:07:36浏览次数:52  
标签:League number rating random CodeForces teams 234E team include


Description:
 

In the autumn of this year, two Russian teams came into the group stage of the most prestigious football club competition in the world — the UEFA Champions League. Now, these teams have already started to play in the group stage and are fighting for advancing to the playoffs. In this problem we are interested in the draw stage, the process of sorting teams into groups.

The process of the draw goes as follows (the rules that are described in this problem, are somehow simplified compared to the real life). Suppose n teams will take part in the group stage (n is divisible by four). The teams should be divided into groups of four. Let's denote the number of groups as m (

CodeForces - 234E   Champions

). Each team has a rating — an integer characterizing the team's previous achievements. The teams are sorted by the rating's decreasing (no two teams have the same rating).

After that four "baskets" are formed, each of which will contain m teams: the first m teams with the highest rating go to the first basket, the following mteams go to the second one, and so on.

Then the following procedure repeats m - 1 times. A team is randomly taken from each basket, first from the first basket, then from the second, then from the third, and at last, from the fourth. The taken teams form another group. After that, they are removed from their baskets.

The four teams remaining in the baskets after (m - 1) such procedures are performed, form the last group.

In the real draw the random selection of teams from the basket is performed by people — as a rule, the well-known players of the past. As we have none, we will use a random number generator, which is constructed as follows. Its parameters are four positive integers x, a, b, c. Every time there is a call to the random number generator, it produces the following actions:

  • calculates ;
  • replaces parameter x by value y (assigns );
  • returns x as another random number.

Operation 

CodeForces - 234E   Champions

 means taking the remainder after division: 

CodeForces - 234E   Champions

CodeForces - 234E   Champions

.

A random number generator will be used in the draw as follows: each time we need to randomly choose a team from the basket, it will generate a random number 

k

. The teams that yet remain in the basket are considered numbered with consecutive integers from 0 to 

s

 - 1, in the order of decreasing rating, where 

s

is the current size of the basket. Then a team number 

CodeForces - 234E   Champions

 is taken from the basket.

Given a list of teams and the parameters of the random number generator, determine the result of the draw.

Input

The first input line contains integer n (4 ≤ n ≤ 64, n is divisible by four) — the number of teams that take part in the sorting. The second line contains four space-separated integers x, a, b, c (1 ≤ x, a, b, c ≤ 1000) — the parameters of the random number generator. Each of the following n lines describes one team. The description consists of the name of the team and its rating, separated by a single space. The name of a team consists of uppercase and lowercase English letters and has length from 1 to 20 characters. A team's rating is an integer from 0 to 1000. All teams' names are distinct. All team's ratings are also distinct.

Output

Print the way the teams must be sorted into groups. Print the groups in the order, in which they are formed in the sorting. Number the groups by consecutive uppercase English letters, starting from letter 'A'. Inside each group print the teams' names one per line, in the order of decreasing of the teams' rating. See samples for a better understanding of the output format.

Examples

Input

81 3 1 7Barcelona 158 Milan 90 Spartak 46 Anderlecht 48 Celtic 32 Benfica 87 Zenit 79 Malaga 16

Output

Group A:BarcelonaBenfica Spartak Celtic Group B: Milan Zenit Anderlecht Malaga

Note

In the given sample the random number generator will be executed four times:

  • ,
  • ,
  • ,
  • .

就是题意难懂,读懂题意直接吗,模拟。

加上读写文件。

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
const int INF = 0x3f3f3f3f;
using namespace std;
typedef long long ll;
typedef double ld;
struct node
{
char name[25];
int rating;
}team[70];
int n,m,x,y,a,b,c;
bool used[70];
bool cmp(node a,node b)
{
return a.rating>b.rating;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int i,g,k,j,h,num;
scanf("%d%d%d%d%d",&n,&x,&a,&b,&c);
for (i=0;i<n;i++) scanf("%s%d",team[i].name,&team[i].rating);
sort(team,team+n,cmp);
m=n/4;
memset(used,false,sizeof(used));
for (g=0;g<m;g++)
{
printf("Group %c:\n",'A'+g);
for (k=0;k<4;k++)
{
y=(x*a+b)%c;
x=y;
h=x%(m-g);
num=-1;
for (j=k*m;;j++)
if (!used[j])
{
num++;
if (num==h) break;
}
used[j]=true;
puts(team[j].name);
}
}
return 0;
}

 

 

 

 

 

标签:League,number,rating,random,CodeForces,teams,234E,team,include
From: https://blog.51cto.com/u_15952369/6036912

相关文章

  • CodeForces - 224D Two Strings
    Description:A subsequence oflength |x| ofstring s = s1s2... s|s| (where |s| isthelengthofstring s)isastring x = sk1sk2... sk|x| (1 ≤......
  • codeforces 1047C. Enlarge GCD(数学)
    题意:给出n个数,求出最少删除几个数可以扩大最大公因子。AC代码:#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<set>#include<map>#includ......
  • CodeForces 948A
    DescriptionBobisafarmer.Hehasalargepasturewithmanysheep.Recently,hehaslostsomeofthemduetowolfattacks.Hethusdecidedtoplacesomeshephe......
  • Codeforces 1322 B. Count Subrectangles(贪心)
    题意:给出序列和序列矩阵是由和决定的问你可以从中截取多少个面积为显然可知的一个性质那就是当序列连续长度为,序列连续长度为,时这个部分序列形成的......
  • Codeforces 1322 A. Unusual Competitions
    题意:给出一个含有的字符串,让你可以选择一个区间进行重新排序,问一共选择的区间长度是多少可以使得字符串最后变成我们只需要从头开始遍历然后找到这种字符,并且使得和......
  • Codeforces 1316 B. String Modification
    题意:反转一个字符串,反转规则为从字符串首字母开头,长度为,反转问一个$k$时会得到一个新串,求字典序最小的新串和,如果字典序相同,则输出最小的。比赛时被卡,疯狂,其实举......
  • Codeforces 1316 D. Nash Matrix(dfs)
    题意:给出一个的棋盘和每个棋盘位置最后能走到的位置,如果一直走不停下来就是,可以停下来就是走到的最后位置,让你输出每个位置的操作字符,上下左右和,停在此位置。我们先找......
  • Codeforces1260 E Tournament(贪心)
    Description:Youareorganizingaboxingtournament,wherenboxerswillparticipate(ispowerof),andyourfriendisoneofthem.Allboxershavedifferents......
  • Codeforces 1155D Beautiful Array
    给你n个数字的数组然后还有一个x,你可以选择一段区间乘上x,输出最大子段和。用一个二维dp来做就行了AC代码:#include<cstdio>#include<cstring>#include<iostream>#include<......
  • codeforces 1257E The Contest(lis)
    题意:3堆数,要求使得第一堆的数为前缀,第三堆数为后缀,第二堆数为剩下的数,要求最少调整多少个数的位置使得要求成立。其实就是就把a1,a2,a3排个序然后拼成一个数组,问题转为一个......