我是铁牌选手

这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一。

天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路。

按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错误也可以是MLE,而且我的内存就是卡了那么一点点,在比赛紧张的状态下人也变傻了吧。

这次的题目难度是两边到中间一次递增的,但是我也不懂榜怎么会那样

 A
Peak

Time Limit: 1 Second      Memory Limit: 65536 KB

A sequence of  integers  is called a peak, if and only if there exists exactly one integer  such that , and  for all , and  for all .

Given an integer sequence, please tell us if it's a peak or not.

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains an integer  (), indicating the length of the sequence.

The second line contains  integers  (), indicating the integer sequence.

It's guaranteed that the sum of  in all test cases won't exceed .

Output

For each test case output one line. If the given integer sequence is a peak, output "Yes" (without quotes), otherwise output "No" (without quotes).

Sample Input

7
5
1 5 7 3 2
5
1 2 1 2 1
4
1 2 3 4
4
4 3 2 1
3
1 2 1
3
2 1 2
5
1 2 3 1 2

Sample Output

Yes
No
No
No
Yes
No
No

A就是判断前一段递增,后一段递减。所以你找到最大值就好了

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
int n,a[N];
int la()
{
int pos=;
for(int i=;i<n;i++)
if(a[pos]<a[i])pos=i;
if(pos==||pos==n-)return ;
for(int i=;i<=pos;i++)
if(a[i-]>=a[i])return ;
for(int i=pos+;i<n;i++)
if(a[i-]<=a[i])return ;
return ;
}
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n;
for(int i=;i<n;i++)cin>>a[i];
cout<<(la()?"Yes":"No")<<"\n";
}
return ;
}
B
King of Karaoke

Time Limit: 1 Second      Memory Limit: 65536 KB

It's Karaoke time! DreamGrid is performing the song Powder Snow in the game King of Karaoke. The song performed by DreamGrid can be considered as an integer sequence , and the standard version of the song can be considered as another integer sequence . The score is the number of integers  satisfying  and .

As a good tuner, DreamGrid can choose an integer  (can be positive, 0, or negative) as his tune and add  to every element in . Can you help him maximize his score by choosing a proper tune?

Input

There are multiple test cases. The first line of the input contains an integer  (about 100), indicating the number of test cases. For each test case:

The first line contains one integer  (), indicating the length of the sequences  and .

The second line contains  integers  (), indicating the song performed by DreamGrid.

The third line contains  integers  (), indicating the standard version of the song.

It's guaranteed that at most 5 test cases have .

Output

For each test case output one line containing one integer, indicating the maximum possible score.

Sample Input

2
4
1 2 3 4
2 3 4 6
5
-5 -4 -3 -2 -1
5 4 3 2 1

Sample Output

3
1

Hint

For the first sample test case, DreamGrid can choose  and changes  to .

For the second sample test case, no matter which  DreamGrid chooses, he can only get at most 1 match.

和上次的题目一样,直接做差就好了

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
int a[N];
unordered_map<int,int>M;
int main()
{
int T;
cin>>T;
while(T--)
{
M.clear();
int n,ma=;
cin>>n;
for(int i=;i<n;i++)cin>>a[i];
for(int i=,x;i<n;i++)
cin>>x,M[a[i]-x]++;
for(auto X:M)ma=max(ma,X.second);
cout<<ma<<"\n";
}
return ;
}
 F
Now Loading!!!

Time Limit: 1 Second      Memory Limit: 131072 KB

DreamGrid has  integers . DreamGrid also has  queries, and each time he would like to know the value of

 

for a given number , where , .

Input

There are multiple test cases. The first line of input is an integer  indicating the number of test cases. For each test case:

The first line contains two integers  and  () -- the number of integers and the number of queries.

The second line contains  integers  ().

The third line contains  integers  ().

It is guaranteed that neither the sum of all  nor the sum of all  exceeds .

Output

For each test case, output an integer , where  is the answer for the -th query.

Sample Input

2
3 2
100 1000 10000
100 10
4 5
2323 223 12312 3
1232 324 2 3 5

Sample Output

11366
45619

有一个向下取整还有向上取整,所以去枚举分母做前缀和优化,卡MLE是真的骚

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+,MD=1e9;
ll sum[][N];
int main()
{
int T;
cin>>T;
while(T--)
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
cin>>sum[][i];
sort(sum[]+,sum[]+n+);
for(int i=;i<;i++)
for(int j=;j<=n;j++)
sum[i][j]=sum[][j]/i+sum[i][j-];
ll ans=;
for(int i=,p;i<m;i++)
{
cin>>p;
ll ans1=,ans2=;
for(int j=;;j++)
{
int pos1=lower_bound(sum[]+,sum[]++n,ans1+)-sum[],pos2=upper_bound(sum[]+,sum[]++n,ans1*p)-sum[]-;
if(pos1==n+)break;
if(pos1<=pos2)ans2=(ans2+sum[j][pos2]-sum[j][pos1-])%MD;
ans1=ans1*p;
}
ans=(ans+ans2*(i+))%MD;
}
cout<<ans<<"\n";
}
return ;
}
 I
Magic Points

Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge

Given an integer , we say a point  on a 2D plane is a magic point, if and only if both  and  are integers, and exactly one of the following conditions is satisfied:

  • and ;

  • and ;

  • and ;

  • and .

It's easy to discover that there are  magic points in total. These magic points are numbered from  to  in counter-clockwise order starting from .

DreamGrid can create  magic lines from these magic points. Each magic line passes through exactly two magic points but cannot be parallel to the line  or  (that is to say, the coordinate axes).

The intersections of the magic lines are called dream points, and for some reason, DreamGrid would like to make as many dream points as possible. Can you tell him how to create these magic lines?

Input

There are multiple test cases. The first line of input contains an integer  (about 100), indicating the number of test cases. For each test case, there is only one integer  ().

Output

For each case output  integers  in one line separated by one space, indicating that in your answer, point  and point  is connected by a line for all .

If there are multiple answers, you can print any of them.

Sample Input

3
2
3
4

Sample Output

0 2 1 3
1 4 2 5 3 6
0 6 1 9 3 8 4 10

Hint

The sample test cases are shown as follow:

4n-4个点让你构造直线而且相交点最多,先考虑让他们同方向的,也就是斜率相同的,但是不一定可以构造出来
但是首先要明确的就是按照边走,i连上n+i
最后一条线刚开始直接把对角线的点相连。但是这样有可能会交于同一点,所以是要找最后一点相连还有他的斜率
n==5也是特殊的,太菜了,哎。不过比赛时这个题目还是可以开的
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
int ans[N];
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
if(n==)cout<<"0 2 1 3\n";
else if(n==)cout<<"1 4 2 5 3 6\n";
else if(n==)cout<<"0 6 1 9 3 8 4 10\n";
else if(n==)cout<<"0 5 1 6 2 7 3 8 11 13\n";
else
{
for(int i=;i<n-;i++)cout<<i<<" "<<n+i<<" ";
cout<<n*-<<" "<<n+n<<"\n";
}
}
return ;
}
J
CONTINUE...?

Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge

DreamGrid has  classmates numbered from  to . Some of them are boys and the others are girls. Each classmate has some gems, and more specifically, the -th classmate has  gems.

DreamGrid would like to divide the classmates into four groups , ,  and  such that:

  • Each classmate belongs to exactly one group.

  • Both  and  consist only of girls. Both  and  consist only of boys.

  • The total number of gems in  and  is equal to the total number of gems in  and .

Your task is to help DreamGrid group his classmates so that the above conditions are satisfied. Note that you are allowed to leave some groups empty.

Input

There are multiple test cases. The first line of input is an integer  indicating the number of test cases. For each test case:

The first line contains an integer  () -- the number of classmates.

The second line contains a string  () consisting of 0 and 1. Let  be the -th character in the string . If , the -th classmate is a boy; If , the -th classmate is a girl.

It is guaranteed that the sum of all  does not exceed .

Output

For each test case, output a string consists only of {1, 2, 3, 4}. The -th character in the string denotes the group which the -th classmate belongs to. If there are multiple valid answers, you can print any of them; If there is no valid answer, output "-1" (without quotes) instead.

Sample Input

5
1
1
2
10
3
101
4
0000
7
1101001

Sample Output

-1
-1
314
1221
3413214

这个就是凑数的题目,可以凑出来的,贪心选择或者找其中的一段区间都是可以的

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
int ans[N];
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
string s;
cin>>s;
long long sum=n*1LL*(n+)/;
if(sum%)cout<<"-1\n";
else
{
sum/=;
for(int i=n-;i>=;i--)
{
if(sum>i)
sum-=(i+),ans[i]=(s[i]=='')?:;
else ans[i]=(s[i]=='')?:;
}
for(int i=;i<n;i++)cout<<ans[i];
cout<<"\n";
}
}
return ;
}
L
Doki Doki Literature Club

Time Limit: 1 Second      Memory Limit: 65536 KB

Doki Doki Literature Club! is a visual novel developed by Team Salvato. The protagonist is invited by his childhood friend, Sayori, to join their high school's literature club. The protagonist then meets the other members of the club: Natsuki, Yuri, and the club president Monika. The protagonist starts to participate in the club's activities such as writing and sharing poetry, and grows close to the four girls. What a lovely story!

A very important feature of the game is its poetry writing mechanism. The player is given a list of various words to select from that will make up his poem. Each girl in the Literature Club has different word preferences, and will be very happy if the player's poem is full of her favorite words.

The poem writing mini-game (from wikipedia)

BaoBao is a big fan of the game and likes Sayori the most, so he decides to write a poem to please Sayori. A poem of  words  is nothing more than a sequence of  strings, and the happiness of Sayori after reading the poem is calculated by the formula

 

where  is the happiness and  is Sayori's preference to the word .

Given a list of  words and Sayori's preference to each word, please help BaoBao select  words from the list and finish the poem with these  words to maximize the happiness of Sayori.

Please note that each word can be used at most once!

Input

There are multiple test cases. The first line of input contains an integer  (about 100), indicating the number of test cases. For each test case:

The first line contains two integers  and  (), indicating the number of words and the length of the poem.

For the following  lines, the -th line contains a string consisting of lowercased English letters  () and an integer  (), indicating the -th word and Sayori's preference to this word. It's guaranteed that  for all .

Output

For each test case output one line containing an integer  and  strings  separated by one space, indicating the maximum possible happiness and the corresponding poem. If there are multiple poems which can achieve the maximum happiness, print the lexicographically smallest one.

Please, DO NOT output extra spaces at the end of each line, or your answer may be considered incorrect!

sequence of  strings  is lexicographically smaller than another sequence of  strings , if there exists a  () such that  for all  and  is lexicographically smaller than .

string  is lexicographically smaller than another string , if there exists a  () such that  for all  and , or  for all  and .

Sample Input

4
10 8
hello 0
world 0
behind 0
far 1
be 2
spring 10
can 15
comes 20
winter 25
if 200
5 5
collegiate 0
programming -5
zhejiang 10
provincial 5
contest -45
3 2
bcda 1
bcd 1
bbbbb 1
3 2
a 1
aa 1
aaa 1

Sample Output

2018 if winter comes can spring be far behind
15 zhejiang provincial collegiate programming contest
3 bbbbb bcd
3 a aa

仅仅是个sort,读懂题意就可以做了

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
struct T
{
string s;
int va;
}a[];
int cmp(T a,T b)
{
return a.va>b.va||a.va==b.va&&a.s<b.s;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int n,m;
cin>>n>>m;
for(int i=;i<n;i++)cin>>a[i].s>>a[i].va;
sort(a,a+n,cmp);
long long sum=;
for(int i=;i<m;i++)
sum+=(m-i)*1LL*a[i].va;
cout<<sum;
for(int i=;i<m;i++)cout<<" "<<a[i].s;
cout<<"\n";
}
return ;
}

Lucky 7


Time Limit: 1 Second      Memory Limit: 65536 KB

BaoBao has just found a positive integer sequence  of length  from his left pocket and another positive integer  from his right pocket. As number 7 is BaoBao's favorite number, he considers a positive integer  lucky if  is divisible by 7. He now wants to select an integer  from the sequence such that  is lucky. Please tell him if it is possible.

Input

There are multiple test cases. The first line of the input is an integer  (about 100), indicating the number of test cases. For each test case:

The first line contains two integers  and  (), indicating the length of the sequence and the positive integer in BaoBao's right pocket.

The second line contains  positive integers  (), indicating the sequence.

Output

For each test case output one line. If there exists an integer  such that  and  is lucky, output "Yes" (without quotes), otherwise output "No" (without quotes).

Sample Input

4
3 7
4 5 6
3 7
4 7 6
5 2
2 5 2 5 2
4 26
100 1 2 4

Sample Output

No
Yes
Yes
Yes

Hint

For the first sample test case, as 4 + 7 = 11, 5 + 7 = 12 and 6 + 7 = 13 are all not divisible by 7, the answer is "No".

For the second sample test case, BaoBao can select a 7 from the sequence to get 7 + 7 = 14. As 14 is divisible by 7, the answer is "Yes".

For the third sample test case, BaoBao can select a 5 from the sequence to get 5 + 2 = 7. As 7 is divisible by 7, the answer is "Yes".

For the fourth sample test case, BaoBao can select a 100 from the sequence to get 100 + 26 = 126. As 126 is divisible by 7, the answer is "Yes".

加上一个数是不是7的倍数,直接做

#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int n,b;
cin>>n>>b;
int f=;
for(int i=,x;i<n;i++)
{
cin>>x;
if((x+b)%==)f=;
}
cout<<(f?"Yes":"No")<<"\n";
}
return ;
}
K
Mahjong Sorting

Time Limit: 1 Second      Memory Limit: 65536 KB

DreamGrid has just found a set of Mahjong with  suited tiles and a White Dragon tile in his pocket. Each suited tile has a suit (Character, Bamboo or Dot) and a rank (ranging from 1 to ), and there is exactly one tile of each rank and suit combination.

Character tiles whose rank ranges from 1 to 9

Bamboo tiles whose rank ranges from 1 to 9

Dot tiles whose rank ranges from 1 to 9

White Dragon tile

As DreamGrid is bored, he decides to play with these tiles. He first selects one of the  suited tiles as the "lucky tile", then he picks  tiles from the set of  tiles and sorts these  tiles with the following rules:

  • The "lucky tile", if contained in the  tiles, must be placed in the leftmost position.

  • For two tiles  and  such that neither of them is the "lucky tile", if

    • is a Character tile and  is a Bamboo tile, or

    • is a Character tile and  is a Dot tile, or

    • is a Bamboo tile and  is a Dot tile, or

    • and  have the same suit and the rank of  is smaller than the rank of ,

    then  must be placed to the left of .

White Dragon tile is a special tile. If it's contained in the  tiles, it's considered as the original (not-lucky) version of the lucky tile during the sorting. For example, consider the following sorted tiles, where "3 Character" is selected as the lucky tile. White Dragon tile, in this case, is considered to be the original not-lucky version of "3 Character" and should be placed between "2 Character" and "4 Character".

As DreamGrid is quite forgetful, he immediately forgets what the lucky tile is after the sorting! Given  sorted tiles, please tell DreamGrid the number of possible lucky tiles.

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains two integers  and  (, ), indicating the number of sorted tiles and the maximum rank of suited tiles.

For the next  lines, the -th line describes the -th sorted tile counting from left to right. The line begins with a capital letter  (), indicating the suit of the -th tile:

  • If , then an integer  () follows, indicating that it's a Character tile with rank ;

  • If , then an integer  () follows, indicating that it's a Bamboo tile with rank ;

  • If , then an integer  () follows, indicating that it's a Dot tile with rank ;

  • If , then it's a White Drangon tile.

It's guaranteed that there exists at least one possible lucky tile, and the sum of  in all test cases doesn't exceed .

Output

For each test case output one line containing one integer, indicating the number of possible lucky tiles.

Sample Input

4
3 9
C 2
W
C 4
6 9
C 2
C 7
W
B 3
B 4
D 2
3 100
C 2
W
C 9
3 9
C 1
B 2
D 3

Sample Output

2
4
7
25

Hint

For the first sample, "2 Character" and "3 Character" are possible lucky tiles.

For the second sample, "8 Character", "9 Character", "1 Bamboo" and "2 Bamboo" are possible lucky tiles.

自己菜做不出来,要把所有的情况都分析到,我太菜了,这个题不想再做了

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int a[N],n,m;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int f=,ans;
scanf("%d%d",&n,&m);
a[n+]=*m+;
for(int i=; i<=n; i++)
{
getchar();
char c=getchar();
if(c!='W')
{
scanf("%d",&a[i]);
if(c=='B')a[i]+=m;
if(c=='D')a[i]+=*m;
}
else f=i;
}
if(n==)ans=*m;
else
{
if(f==)
if(a[]>a[])ans=;
else ans=*m-n+;
else
{
if(f==)ans=a[]-;
else
{
if(a[]>a[]&&f!=)ans=;
else ans=a[f+]-a[f-]-(f!=);
}
}
}
cout<<ans<<"\n";
}
return ;
}
 D
Sequence Swapping

Time Limit: 1 Second      Memory Limit: 65536 KB

BaoBao has just found a strange sequence {<, >, <, >, , <, >} of length  in his pocket. As you can see, each element <, > in the sequence is an ordered pair, where the first element  in the pair is the left parenthesis '(' or the right parenthesis ')', and the second element  in the pair is an integer.

As BaoBao is bored, he decides to play with the sequence. At the beginning, BaoBao's score is set to 0. Each time BaoBao can select an integer , swap the -th element and the -th element in the sequence, and increase his score by , if and only if ,  '(' and  ')'.

BaoBao is allowed to perform the swapping any number of times (including zero times). What's the maximum possible score BaoBao can get?

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains an integer  (), indicating the length of the sequence.

The second line contains a string  () consisting of '(' and ')'. The -th character in the string indicates , of which the meaning is described above.

The third line contains  integers  (). Their meanings are described above.

It's guaranteed that the sum of  of all test cases will not exceed .

Output

For each test case output one line containing one integer, indicating the maximum possible score BaoBao can get.

Sample Input

4
6
)())()
1 3 5 -1 3 2
6
)())()
1 3 5 -100 3 2
3
())
1 -1 -1
3
())
-1 -1 -1

Sample Output

24
21
0
2

Hint

For the first sample test case, the optimal strategy is to select  in order.

For the second sample test case, the optimal strategy is to select  in order.

 这个dp就是去找(,找到它最右可以到达的位置

 然后你可以找一个这个)前一个),保证他也最优 
#include<bits/stdc++.h>
using namespace std;
const int N=;
typedef long long ll;
char s[N];
ll v[N],dp[N][N],sum[N],F[N],nxt[N];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,f=,tot=;
scanf("%d%s",&n,s+);
for(int i=; i<=n; i++)scanf("%lld",&v[i]);
for(int i=n; i>; i--)if(s[i]=='(')F[tot++]=i;
for(int i=; i<=n; i++) sum[i]=sum[i-]+(s[i]==')'?v[i]:);
memset(nxt,,sizeof(nxt));
for(int i=; i<=n; i++)
if(s[i]==')')
{
if(f) nxt[f]=i;
f=i;
}
for(int i=; i<=n; i++) dp[i][]=-(1LL<<);
ll ans=;
for(int i=; i<tot; i++)
{
for(int j=F[i]+; j<=n; j++)
if(s[j]==')') dp[i][j]=v[F[i]]*(sum[j]-sum[F[i]])+dp[i-][j];
for(int j=n; j>=F[i]; j--)
if(s[j]==')') dp[i][j]=max(dp[i][nxt[j]],dp[i][j]);
for(int j=F[i]-; j>=; j--)
if(s[j]==')') dp[i][j]=max(dp[i-][j],dp[i][nxt[j]]);
for(int j=; j<=n; j++) if(s[j]==')')ans=max(ans,dp[i][j]);
}
printf("%lld\n",ans);
}
return ;
}

使用滚动数组优化

#include<bits/stdc++.h>
using namespace std;
const int N=;
typedef long long ll;
char s[N];
ll v[N],dp[][N],sum[N],F[N],nxt[N];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,f=,tot=,cur=;
scanf("%d%s",&n,s+);
for(int i=; i<=n; i++)scanf("%lld",&v[i]);
for(int i=n; i>; i--)if(s[i]=='(')F[tot++]=i;
for(int i=; i<=n; i++) sum[i]=sum[i-]+(s[i]==')'?v[i]:);
memset(nxt,,sizeof(nxt));
for(int i=; i<=n; i++)
if(s[i]==')')
{
if(f) nxt[f]=i;
f=i;
}
for(int i=; i<=n; i++) dp[][i]=dp[][i]=;
dp[][]=dp[][]=-(1LL<<);
ll ans=;
for(int i=; i<tot; i++)
{
for(int j=F[i]+; j<=n; j++)
if(s[j]==')') dp[cur][j]=v[F[i]]*(sum[j]-sum[F[i]])+dp[cur^][j];
for(int j=n; j>=F[i]; j--)
if(s[j]==')') dp[cur][j]=max(dp[cur][nxt[j]],dp[cur][j]);
for(int j=F[i]-; j>=; j--)
if(s[j]==')') dp[cur][j]=max(dp[cur^][j],dp[cur][nxt[j]]);
for(int j=; j<=n; j++) if(s[j]==')')ans=max(ans,dp[cur][j]);
cur^=;
}
printf("%lld\n",ans);
}
return ;

Magic 12 Months


Time Limit: 1 Second      Memory Limit: 65536 KB

It's New Year's Eve, and it's also the best time of the year to play the card game Magic 12 Months to pray for good luck of the coming year. BaoBao has just found a deck of standard 52 playing cards (without Jokers) in his pocket and decides to play the game. The rules are as follows:

  1. Setup

    1. Remove the four 'K's from the 52 cards.

    2. Shuffle the remaining 48 cards and divide them face down into 12 piles (4 cards per pile) with equal probability.

  2. Gameplay

    1. Let .

    2. Flip the card on the top of the -th pile, check its rank , and discard the card.

    3. If  is a number, let ; If , let ; If , let ; If , let .

    4. If the -th pile is empty, the game ends; Otherwise go back to step 2.2.

When the game ends, having all the 4 cards of rank  flipped and discarded indicates that the -th month in the coming year is a lucky month.

BaoBao is in the middle of the game and has discarded  cards. He wants to know the probability that the -th month of the coming year is a lucky month for all  when the game ends. Given these  cards, please help him calculate the answer.

Input

There are multiple test cases. The first line of input contains an integer  (about 100) -- the number of test cases. For each test case:

The first and only line contains an integer  () -- the number of flipped cards, followed by the rank of the  cards  () separated by a space in the order they are flipped. It's guaranteed that the input describes a valid and possible situation of the game.

Output

For each test case output one line containing 12 numbers separated by a space, where the -th number indicates the probability that the -th month of the coming year is a lucky month.

You should output a probability in its simplest fraction form  where  and  are coprime. Specifically, if the probability equals 0, you should output 0; If the probability equals 1, you should output 1.

Please, DO NOT output extra spaces at the end of each line, or your answer may be considered incorrect!

Sample Input

3
30 9 Q 10 J Q 10 J 10 J J 8 5 7 6 5 7 6 7 6 6 3 A 2 4 A 2 4 2 4 4
0
7 2 A 3 A 4 A A

Sample Output

1 2/3 2/5 1 1/2 1 2/3 2/5 2/5 2/3 1 1/2
1 1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2
1 0 0 0 0 0 0 0 0 0 0 0

想到了和第一堆有关,但是还没推出来

#include<bits/stdc++.h>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
typedef long long ll;
ll C(int n,int m)
{
if(m>n)return ;
ll ans=;
for(int i=n-m+; i<=n; i++)ans*=i;
for(int i=; i<=m; i++)ans/=i;
return ans;
}
int a[];
int main()
{
int t;
cin>>t;
while(t--)
{
for(int i=; i<=; i++)a[i]=;
int n;
cin>>n;
string s;
for(int i=,x; i<n; i++)
{
cin>>s;
if(s=="")x=;
else if(s=="A")x=;
else if(s=="J")x=;
else if(s=="Q")x=;
else x=s[]-;
a[x]--;
}
cout<<;
for(int i=; i<=; i++)
{
//dbg(a[i]);
if(!a[i])cout<<"";
else if(!a[])cout<<"";
else
{
int m=-n;
ll B=C(m,a[])*C(m-a[],a[i]),A=;
for(int j=a[]; j<=m; j++)A+=C(j-,a[]-)*C(j-a[],a[i]);
ll d=__gcd(A,B);
if(!A)cout<<"";
else if(A==B)cout<<"";
else cout<<" "<<A/d<<"/"<<B/d;
}
}
cout<<"\n";
}
return ;
}

2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple的更多相关文章

  1. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - L Doki Doki Literature Club

    Doki Doki Literature Club Time Limit: 1 Second      Memory Limit: 65536 KB Doki Doki Literature Club ...

  2. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - M Lucky 7

    Lucky 7 Time Limit: 1 Second      Memory Limit: 65536 KB BaoBao has just found a positive integer se ...

  3. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - J CONTINUE...?

    CONTINUE...? Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge DreamGrid has  clas ...

  4. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - B King of Karaoke

    King of Karaoke Time Limit: 1 Second      Memory Limit: 65536 KB It's Karaoke time! DreamGrid is per ...

  5. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple -A Peak

    Peak Time Limit: 1 Second      Memory Limit: 65536 KB A sequence of  integers  is called a peak, if ...

  6. ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)

    #include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ ...

  7. The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - F 贪心+二分

    Heap Partition Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A sequence S = { ...

  8. The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - C 暴力 STL

    What Kind of Friends Are You? Time Limit: 1 Second      Memory Limit: 65536 KB Japari Park is a larg ...

  9. ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp

    Seven Segment Display Time Limit: 1 Second      Memory Limit: 65536 KB A seven segment display, or s ...

随机推荐

  1. 访问FTP站点下载文件,提示“当前的安全设置不允许从该位置下载文件”的解决方案

    访问FTP站点下载文件,提示“当前的安全设置不允许从该位置下载文件”的解决方案: 打开客戶端浏览器--工具---internet-安全-自定义级别-选择到低到中低. 然后点受信任站点,把你要访问的站点 ...

  2. 2018.6.29 JavaScript

    一.使用JS数组实现冒泡排序 二.创建Teacher对象,添加(姓名.年龄.地址.学生对象[学生姓名,学生性别])属性 要求: 创建多个老师对象,每个老师下管理多个学生,显示每个老师下所有的学生信息 ...

  3. Java中ArrayList的对象引用问题

    前言事件起因是由于同事使用ArrayList的带参构造方法进行ArrayList对象复制,修改新的ArrayList对象中的元素(对象)的成员变量时也会修改原ArrayList中的元素(对象)的成员变 ...

  4. python生成随机数

    import random rnd=rand.uniform(0,10)

  5. java实现微信扫一扫详解

    java实现微信扫一扫详解 一.微信JS-SDK参数配置及查找 JS安全域名配置(查找:微信公众号里-公众号设置-功能设置页) 注:1.安全域名外网必须可以访问的到  2.域名不能有下划线  3.要将 ...

  6. 获取Bing每日壁纸用作首屏大图

    获取Bing每日壁纸用作首屏大图 Bing 搜索每天都会更换一张精美的图片作为壁纸,除了特殊时候不太好看外(比如春节那几天),没多大问题.移动端还有上每日故事,与图片现配.现在我的博客首屏图片就是Bi ...

  7. shell脚本,awk结合正则来打印文件里面的内容。

    文件内容如下:key1abc d key2 1.想得到如下结果: abc d 2.想得到如下结果: key1key2

  8. 【图论】[USACO]控制公司 Controlling Companies

    玄妙的搜索 题目描述 有些公司是其他公司的部分拥有者,因为他们获得了其他公司发行的股票的一部分.(此处略去一句废话)据说,如果至少满足了以下三个条件之一,公司A就可以控制公司B了: 公司A = 公司B ...

  9. 【NTT】bzoj3992: [SDOI2015]序列统计

    板子题都差点不会了 Description 小C有一个集合S,里面的元素都是小于M的非负整数.他用程序编写了一个数列生成器,可以生成一个长度为N的数 列,数列中的每个数都属于集合S.小C用这个生成器生 ...

  10. 第二篇:ssh.invoke_shell() 切换root出现的新问题

    接上一篇:按照上一篇的方式,在没有对ssh.invoke_shell()执行后的登录提示符进行判断的话,那边有部分机器就回因为返回为空导致程序卡死. 正常机器  ssh.recv(9999)  命令返 ...