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?
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.
For each test case, print one line containing the answer. Print the answer rounded to exactly 9 decimal digits.
3952925592
0.0000000000.1666666670.194444444
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?
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.
For each test case, print one line containing the answer. Print the answer rounded to exactly 9 decimal digits.
3952925592
0.0000000000.1666666670.194444444
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?
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.
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.
23 2A F B F C TB T C F D F1 3A FB FC F
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?
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.
For each test case, print one line consists of 'Square' if the shape is a square, otherwise print 'Rectangle' if it is a rectangle.
310 1013 200300 300
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
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.
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.
For each test case print one line consists of one integer representing the maximum hamming distance between all possible pairs from the given integers.
221253123
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;}
- UPC 2017 Summer Training 1
- UPC 2017 Summer Training 1
- UPC 2017 Summer Training 1
- UPC 2017 Summer Training 1
- UPC 2017 Summer Training 5
- UPC 2017 Summer Training 5
- UPC 2017 Summer Training 6 A,D,I
- UESTC 2017 Summer Training #1 Div.2
- BUPT 2017 summer training (for 16) #1
- 2017 Summer Training Day1
- BUPT Summer training 1 总结
- SDKD 2017 Summer Single Training #01(训练赛1)
- 2017 Xian ACM Summer Training Warm-up Exercise 1
- UESTC 2017 Summer Training #2 Div.2
- E- Refraction----(2015 NEUQ_ACM summer training #1)
- ecjtu-summer training #1 F (UVA 11461)
- Tri_integral Summer Training 6
- BUPT-SUMMER-TRAINING-搜索
- GPU编程自学1 —— 引言
- hdoj 6043(2017 Multi-University Training Contest
- 对于PHP语法你了解多少?
- bsgs(数论)
- SQL Server 时间查询整理
- UPC 2017 Summer Training 1
- 【JavaSE学习笔记】集合02_Set
- 关于drawble文件夹和mipmap文件夹下的图片
- java.io.IOException: invalid constant type: 15
- mybatis调用ORACLE存储过程
- plsql
- WebRTC系列(2):room server,signaling server 和客户端之间的交互
- 【转】维护工厂库存的一般设置
- 你能接受0.999...=1吗?