UPC 2017 Summer Training 1

来源:互联网 发布:js strict mode 编辑:程序博客网 时间:2024/05/29 16:22

A - Arcade Game

 
Statements

Arcade mall is a new modern mall. It has a new hammer game called "Arcade Game". In this game you're presented with a number n which is hanged on a wall on top of a long vertical tube, at the bottom of the tube there is a button that you should hit with your hammer.

When you hit the button with all your force (as you always do), a ball is pushed all over the tube and hit the number n. The number n flies in the air and it's digits fall back in any random permutation with uniform probability.

If the new number formed is less than or equal to the previous number, the game ends and you lose what ever the new number is. Otherwise (if the number is greater than the previous number), you are still in the game and you should hit the button again.

You win if the new number formed is greater than the previous number and it is equal to the greatest possible permutation number.

Can you compute the probability of winning?

Input

The first line of the input contains the number of test cases T. Following that there are T lines represents T test cases. In each line, there is a single integer (1 ≤ n ≤ 109) the target number. The digits of n are all unique, which means that any 2 digits of n are different.

Output

For each test case, print one line containing the answer. Print the answer rounded to exactly 9 decimal digits.

Example
Input
3952925592
Output
0.0000000000.1666666670.194444444
Note

In the first test case, the answer is 0 because 952 is greater than all 2,5 and 9 permutations so you can't win, whatever you do.

In the second test case, the answer is 0.166666667 because you may win by getting number 952 with probability 1/6.

In the third test case the answer is 0.194444444 because you may win by getting number 952 in round1 with probability 1/6 or you can win by getting number 925 in round 1 and then 952 in round 2 with probability 1/6 * 1/6.



Statements

Arcade mall is a new modern mall. It has a new hammer game called "Arcade Game". In this game you're presented with a number n which is hanged on a wall on top of a long vertical tube, at the bottom of the tube there is a button that you should hit with your hammer.

When you hit the button with all your force (as you always do), a ball is pushed all over the tube and hit the number n. The number n flies in the air and it's digits fall back in any random permutation with uniform probability.

If the new number formed is less than or equal to the previous number, the game ends and you lose what ever the new number is. Otherwise (if the number is greater than the previous number), you are still in the game and you should hit the button again.

You win if the new number formed is greater than the previous number and it is equal to the greatest possible permutation number.

Can you compute the probability of winning?

Input

The first line of the input contains the number of test cases T. Following that there are T lines represents T test cases. In each line, there is a single integer (1 ≤ n ≤ 109) the target number. The digits of n are all unique, which means that any 2 digits of n are different.

Output

For each test case, print one line containing the answer. Print the answer rounded to exactly 9 decimal digits.

Example
Input
3952925592
Output
0.0000000000.1666666670.194444444
Note

In the first test case, the answer is 0 because 952 is greater than all 2,5 and 9 permutations so you can't win, whatever you do.

In the second test case, the answer is 0.166666667 because you may win by getting number 952 with probability 1/6.

In the third test case the answer is 0.194444444 because you may win by getting number 952 in round1 with probability 1/6 or you can win by getting number 925 in round 1 and then 952 in round 2 with probability 1/6 * 1/6.



ac代码:

#include <stdio.h> #include <cmath>#include <cstring>#include <queue>#include <algorithm>#define ll long long using namespace std;const int maxn=100+5;ll t;ll n;char s[maxn];int a[maxn];int fa[maxn]={1,1};int main(){for(int i=2;i<=10;i++)fa[i]=fa[i-1]*i;scanf("%lld",&t);while(t--){scanf("%s",s);int num=strlen(s);//printf("num==%d\n",num);int cnt=0;while(next_permutation(s,s+num)){cnt++;}if(cnt==0){printf("0.000000000\n");}else{double ans,ave,ans_ave;ave=1.0/(fa[num]*1.0);ans=ave;ans_ave=ave;for(int i=1;i<cnt;i++){ans=ans+ans*ave;}printf("%.9f\n",ans);}}return 0;}

B - Unlucky Teacher

Ali is a teacher in one of Kuwait universities. Last week he made a multi-choice test for his students. After the test, he marked some papers before collecting all papers and going home. However, he discovered that he forgot the solution key at the university. He is sure that he didn't make any mistake in correcting papers, so in order to complete the correction process, he decided to extract the solution key from the papers that have already been marked.

Ali knows that each question should have one and only one correct choice, can you help him with extracting the correct answers for all the questions?

Input

The first line of the input is a single integer T, the number of test cases. Each test case will consist of several lines. The first line contains 2 integers separated by a single space: (1 ≤ Q ≤ 100 and 0  ≤ M ≤ 100) representing the number of questions in the test, and the number of the corrected papers, respectively. Each of the next M lines will contain 2Q upper case letters separated by single spaces: qi ai (  {'A','B','C','D'} and {'T','F'}) representing the student answer for the ith question (from a corrected paper) and the status of the student answer 'T' if it is True or 'F' if it is False.

Output

For each test case, print a single line contains Q characters separated by single spaces:  {'A','B','C','D','?'}) representing the correct answer of ith question that could be extracted from the given corrected papers or '?' in case it could not be determined.

Example
Input
23 2A F B F C TB T C F D F1 3A FB FC F
Output
B ? CD



#include <stdio.h> #include <cmath>#include <cstring>#include <queue>#include <algorithm>#define ll long long using namespace std;int t;int q,m;char s[105][500];int ans[105];int vis[105];int vis_a[105][4];int main(){scanf("%d",&t);while(t--){scanf("%d%d",&q,&m);getchar();for(int i=0;i<m;i++){gets(s[i]);//printf("%s\n",s[i]);//printf("\n");}memset(ans,-1,sizeof(ans));memset(vis,0,sizeof(vis));memset(vis_a,0,sizeof(vis_a));int num;for(int i=0;i<m;i++){num=1;for(int j=0;j<strlen(s[i]);j=j+4){//printf("*****===%c====%c\n",s[i][j],s[i][j+2]);if(s[i][j+2] == 'T'){ans[num]=s[i][j]-65;}else{if(!vis_a[num][s[i][j]-65]){vis_a[num][s[i][j]-65]=1;vis[num]++;}}num++;}/*for(int k=0;k<num;k++){printf("%d ",ans[k]);}printf("\n");*/}int flag;for(int i=1;i<=q;i++){if(ans[i]==-1 && vis[i]==3){for(int j=0;j<4;j++){if(!vis_a[i][j]){ans[i]=j;}}}}if(ans[1]==-1){printf("?");}else{printf("%c",ans[1]+65);}for(int i=2;i<=q;i++){if(ans[i]==-1){printf(" ?");}else{printf(" %c",ans[i]+65);}}printf("\n");}return 0;}


F - Geometry

 

Geometry is a very important field in mathematics, Squares and rectangles are essential shapes in geometry, both of them have 4 right angles, but a square is a special case of a rectangle where width and height are the same.

The figure below shows a square on the left and a rectangle on the right:

If you have the width and the height of a 4 right angled shape, can you figure out if it is a square or a rectangle?

Input

The first line contains T, the number of test cases, for each test case there is a line with two integers (1 ≤ w, h ≤ 1, 000, 000) representing width and height, respectively.

Output

For each test case, print one line consists of 'Square' if the shape is a square, otherwise print 'Rectangle' if it is a rectangle.

Example
Input
310 1013 200300 300
Output
SquareRectangleSquare


#include <stdio.h> #include <cmath>#include <cstring>#include <queue>#include <algorithm>#define ll long long using namespace std;int t;ll a,b;int main(){scanf("%d",&t);while(t--){scanf("%lld%lld",&a,&b);if(a==b){printf("Square\n");}elseprintf("Rectangle\n");}return 0;}

I - Salem

 

Statements

Salem is known to be one of the best competitive programmers in the region. However, he always finds a hard time understanding the concept of the hamming distance. The hamming distance of two numbers is defined as the number of different digits in their binary representations (leading zeros are used if necessary to make the binary representations have the same length). For example the hamming distance between 12 and 5 is 2 since their binary representations are 1100 and 0101 respectively and they differ in the first and fourth positions.

Recently, Salem got a problem that he needs your help to solve. He is given Nintegers and asked to get the maximum among the hamming distances of all possible pairs of the given integers.

Input

The first line of the input will be a single integer T representing the number of test cases. Followed by T test cases. Each test case will start with a line with single integer (2 ≤ N ≤ 100) representing the number of the integers. Each of the following N lines contains one of the integers (1 ≤ Ai ≤ 10, 000) from the list of the integers.

Output

For each test case print one line consists of one integer representing the maximum hamming distance between all possible pairs from the given integers.

Example
Input
221253123
Output
22


ac代码


#include <stdio.h> #include <cmath>#include <cstring>#include <queue>#include <algorithm>#define ll long long using namespace std;int t;int n;int a[105];int main(){scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&a[i]);}int tmp=0,cnt;int mann=-1;for(int i=0;i<n;i++){for(int j=i+1;j<n;j++){tmp=a[i]^a[j];//printf("***%d***\n",tmp);cnt=0;while(tmp){if(tmp%2){cnt++;}tmp=tmp/2;}if(cnt >= mann)mann=cnt ;}}printf("%d\n",mann);}return 0;}







原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 全脸做激光去黄褐斑后脸发红怎么办 上传到微云中的视频下载不了怎么办 微云保存的小电影下载不了怎么办 苹果手机下载有云朵下载不了怎么办 手机下载登录忘了密码了怎么办 软软件被手机加密忘了密码怎么办 苹果手机想下载东西忘了密码怎么办 已经不念书几年了突然想上学怎么办 江湖风云录把王老爷子杀了怎么办 练扫踢胫骨旁边的肌肉受伤了怎么办 四个月宝宝没抱住摔了头部怎么办 老公老是跟年轻的小姑娘聊天怎么办 老婆出轨老公想离婚又舍不得怎么办 孕妇打完无痛分娩针就想睡觉怎么办 熟食店开空调菜品吹的很干怎么办 不锈钢锅在液化气烧了发黄怎么办 在小镇门面卤菜店不好卖怎么办? 被辣椒辣到嘴唇了该怎么办 沁园净水机不制水指示灯不亮怎么办 太辣了辣得胃疼怎么办 出现连接问题或mmi码无效怎么办 存折丢了怎么办卡号也不记得了 车内皮子被烂苹果腐蚀有印怎么办 锅被腐蚀后变黑色应该怎么办 后厨炉灶里的炉芯进水了怎么办 小儿九个月老是流黄鼻子该怎么办 肉炖的老了不烂怎么办 吃了凉东西现在一直打嗝应该怎么办 喝了很多水还是觉得口渴怎么办 刚买的猪肝没洗直接炒了怎么办 四个多月的宝宝吃了脏东西怎么办 狗吃了脏东西拉稀呕吐怎么办 五个月宝宝怕吃药导致奶不喝怎么办 蒸锅锅盖吸住了怎么办锅比锅盖要大 豇豆没熟孕妇吃了中毒怎么办 孩子积食拉不出粑粑憋的直哭怎么办 2岁宝宝总是半夜拉粑粑怎么办 金毛拉很臭的稀粑粑怎么办 点餐系统登录后没有菜单怎么办? 环亚在线微交易亏了钱怎么办 钢管舞报了教练班觉得学不会怎么办