第7届福建省赛练习赛

来源:互联网 发布:java命令模式作用 编辑:程序博客网 时间:2024/06/04 18:12

A - Card Game (First Edition)


 

Fat brother and Maze are playing a kind of special (hentai) game with some cards. There are N*2 cards in this game for the players to use, this is the card deck. The game goes for N rounds and in each round, Fat Brother would draw one card from the remaining card deck randomly and then Maze would draw one card from the remaining card deck randomly. Then they compare for the integers which is written on these two cards. The player with the higher number wins this round and score 1 victory point. And then these two cards are removed from the game such that they would not appear in the later rounds. As we all know, Fat Brother is very clever, so he would like to know the expect number of the victory points he could get if he knows all the integers written in these cards.

Note that the integers written on these N*2 cards are pair wise distinct. At the beginning of this game, each player has 0 victory point.

Input

The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.

Then T cases follow, each case contains an integer N (1 <= N<=10000) which described before. Then follow one line with N*2 integers, which indicate the integers in these cards.

All the integers are positive and no morethan 10000000.

Output

For each case, output the case number first, and then output the expect number of the victory points Fat Brother could get in this game. The answer should be rounded to 2 digits after the decimal point.

Sample Input
211 221 2 3 4
Sample Output
Case 1: 0.50Case 2: 1.00




#include<iostream>#include<algorithm>using namespace std;int a[20010];int main(){int t,n,m=1,k;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=1;i<=2*n;i++)scanf("%d",&a[i]);printf("Case %d: %.2f\n",m++,n/2.0);}}


B - Card Game (Second Edition)

Fat brother and Maze are playing a kind of special (hentai) game with some cards. In this game, every player gets N cards at first and these are their own card deck. The game goes for N rounds and in each round, Fat Brother and Maze would draw one card from their own remaining card deck randomly and compare for the integer which is written on the cards. The player with the higher number wins this round and score 1 victory point. And then these two cards are removed from the game such that they would not appear in the later rounds. As we all know, Fat Brother is very clever, so he would like to know the expect number of the victory points he could get if he knows all the integers written in these cards.

Note that the integers written on these N*2 cards are pair wise distinct. At the beginning of this game, each player has 0 victory point.

Input

The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.

Then T cases follow, each case contains an integer N (1 <=N<=10000) which described before. Then follow two lines with N integers each. The first N integers indicate Fat Brother’s cards and the second N integers indicate Maze’s cards.

All the integers are positive and no more than 10000000.

Output

For each case, output the case number first, and then output the expect number of victory points Fat Brother would gets in this game. The answer should be rounded to 2 digits after the decimal point.

Sample Input
211221 32 4

Sample Output
Case 1: 0.00Case 2: 0.50



#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;int b[10010],m[10010];int t,n,k=1;int sum,count=0,p;int main(){scanf("%d",&t);while(t--){p=0;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d",&b[i]);for(int i=0;i<n;i++)scanf("%d",&m[i]);sort(m,m+n);for(int i=0;i<n;i++){ p+=lower_bound(m,m+n,b[i])-m;}printf("Case %d: %.2f\n",k++,p*1.0/n);}}


C - Card Game (Third Edition)

 


Fat brother and Maze are playing a kind of special (hentai) game with some cards. In this game, every player gets N cards at first and these are their own card decks. Each of these two decks of cards is stacking together at the beginning of the game, and their order would not change during this game. The game goes for N rounds and in each round, Fat Brother and Maze would draw one card from the top of their own remaining card deck and sum these two integers together. If this number is greater than 10, Fat Brother would score 1 victory point and otherwise Maze would score 1 victory points. And then these two cards are removed from the game such that they would not appear in the later rounds. As we all know, Fat Brother is very clever, so he would like to know the number of the victory points he could get if he knows all the integers written in these cards. At the beginning of this game, each player has 0 victory point.

Input

The first line of the date is an integer T (1 <= T <= 100), which is the number of the text cases.

Then T cases follow, each case contains an integer N (1 <= N <= 10000) which described before. Then follow two lines with N integers each. The first N integers indicate the cards which Fat Brother gets from top to bottom, and the second N integers indicate the cards which Maze gets from top to bottom.

All the integers are positive and least than 10.

Output

For each case, output the case number first, and then output the number of victory points Fat Brother would gets in this game.

Sample Input
215623 43 4
Sample Output
Case 1: 1Case 2: 0



#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;int b[10010],m[10010];int i,n,t,k=1;int main(){scanf("%d",&t);while(t--){int p=0;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&b[i]);for(i=0;i<n;i++)scanf("%d",&m[i]);for(int i=0;i<n;i++){ if(b[i]+m[i]>10) p++;}printf("Case %d: %d\n",k++,p);}}

E - Cutting Game

 

Fat brother and Maze are playing a kind of special (hentai) game with a piece of gold of length N where N is an integer. Although, Fat Brother and Maze can buy almost everything in this world (except love) with this gold, but they still think that is not convenient enough. Just like if they would like to buy the moon with M lengths of the gold, the man who sold the moon need to pay back Fat Brother and Maze N-M lengths of the gold, they hope that they could buy everything they can afford without any change. So they decide to cut this gold into pieces. Now Fat Brother and Maze would like to know the number of the pieces they need to cut in order to make them fulfill the requirement. The number of the gold pieces should be as small as possible. The length of each piece of the gold should be an integer after cutting.

Input

The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.

Then T cases follow, each case contains an integer N (1 <= N <= 10^9) indicated the length of the gold.

Output

For each case, output the case number first, and then output the number of the gold pieces they need to cut.

Sample Input
13
Sample Output
Case 1: 2
Hint

In the first case, the gold can be cut into 2 pieces with length 1 and 2 in order to buy everything they can afford without change.

#include<stdio.h>int main(){int t,n,s,k=1;scanf("%d",&t);for(int i=1;i<=t;i++){scanf("%d",&n);s=0;while(n){n>>=1;s++;}printf("Case %d: %d\n",k++,s);}}


原创粉丝点击