2016 ICPC 青岛站 A【water】、B【模拟】、C【规律】、D【概率】
2017-12-03 23:04
417 查看
A - Relic Discovery
Recently, paleoanthropologists have found historical remains on an island in the Atlantic Ocean. The most inspiring thing is that they excavated in a magnificent cave and found that it was a huge tomb. Inside the construction,researchers identified a large number of skeletons, and funeral objects including stone axe, livestock bones and murals. Now, all items have been sorted, and they can be divided into N types. After they were checked attentively, you are told that there are AiAi items of the i-th type. Further more, each item of the i-th type requires BiBi million dollars for transportation, analysis, and preservation averagely. As your job, you need to calculate the total expenditure.
Input
The first line of input contains an integer T which is the number of test cases. For each test case, the first line contains an integer N which is the number of types. In the next N lines, the i-th line contains two numbers AiAi and BiBi as described above. All numbers are positive integers and less than 101.
Output
For each case, output one integer, the total expenditure in million dollars.
Sample Input
1
2
1 2
3 4
Sample Output
14
水题求个乘再累加
B - Pocket Cube
The Pocket Cube, also known as the Mini Cube or the Ice Cube, is the 2 × 2 × 2 equivalence of a Rubik’s Cube.
The cube consists of 8 pieces, all corners.
Each piece is labeled by a three dimensional coordinate (h, k, l) where h, k, l ∈ {0, 1}. Each of the six faces owns four small faces filled with a positive integer.
For each step, you can choose a certain face and turn the face ninety degrees clockwise or counterclockwise.
You should judge that if one can restore the pocket cube in one step. We say a pocket cube has been restored if each face owns four same integers.
Input
The first line of input contains one integer N(N ≤ 30) which is the number of test cases.
For each test case, the first line describes the top face of the pocket cube, which is the common 2 × 2 face of pieces
labelled by (0, 0, 1),(0, 1, 1),(1, 0, 1),(1, 1, 1). Four integers are given corresponding to the above pieces.
The second line describes the front face, the common face of (1, 0, 1),(1, 1, 1),(1, 0, 0),(1, 1, 0). Four integers are
given corresponding to the above pieces.
The third line describes the bottom face, the common face of (1, 0, 0),(1, 1, 0),(0, 0, 0),(0, 1, 0). Four integers are
given corresponding to the above pieces.
The fourth line describes the back face, the common face of (0, 0, 0),(0, 1, 0),(0, 0, 1),(0, 1, 1). Four integers are
given corresponding to the above pieces.
The fifth line describes the left face, the common face of (0, 0, 0),(0, 0, 1),(1, 0, 0),(1, 0, 1). Four integers are given
corresponding to the above pieces.
The six line describes the right face, the common face of (0, 1, 1),(0, 1, 0),(1, 1, 1),(1, 1, 0). Four integers are given
corresponding to the above pieces.
In other words, each test case contains 24 integers a, b, c to x. You can flat the surface to get the surface development
as follows.
+
| q | r | a | b | u | v |
+
| s | t | c | d | w | x |
+
| e | f |
+
| g | h |
+
| i | j |
+
| k | l |
+
| m | n |
+
| o | p |
+
Output
For each test case, output YES if can be restored in one step, otherwise output NO.
Sample Input
4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
6 6 6 6
1 1 1 1
2 2 2 2
3 3 3 3
5 5 5 5
4 4 4 4
1 4 1 4
2 1 2 1
3 2 3 2
4 3 4 3
5 5 5 5
6 6 6 6
1 3 1 3
2 4 2 4
3 1 3 1
4 2 4 2
5 5 5 5
6 6 6 6
Sample Output
YES
YES
YES
NO
分析:二阶魔方模拟题,共计六种情况。
坑点:初始化不能为相同值,至今莫名其妙。
C - Pocky
Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decorative stripes in the coating, of length L.
While the length of remaining pocky is longer than d, we perform the following procedure. We break the pocky at any point on it in an equal possibility and this will divide the remaining pocky into two parts. Take the left part and eat it. When it is not longer than d, we do not repeat this procedure.
Now we want to know the expected number of times we should repeat the procedure above. Round it to 6 decimal places behind the decimal point.
Input
The first line of input contains an integer N which is the number of test cases. Each of the N lines contains two float-numbers L and d respectively with at most 5 decimal places behind the decimal point where 1 ≤ d, L ≤ 150.
Output
For each test case, output the expected number of times rounded to 6 decimal places behind the decimal point in a line.
Sample Input
6
1.0 1.0
2.0 1.0
4.0 1.0
8.0 1.0
16.0 1.0
7.00 3.00
Sample Output
0.000000
1.693147
2.386294
3.079442
3.772589
1.847298
1+lnx的规律
D - Lucky Coins
Bob has collected a lot of coins in different kinds. He wants to know which kind of coins is lucky. He finds out a lucky kind of coins by the following way. He tosses all the coins simultaneously, and then removes the coins that come up tails. He then tosses all the remaining coins and removes the coins that come up tails. He repeats the previous step until there is one kind of coins remaining or there are no coins remaining. If there is one kind of coins remaining, then this kind of coins is lucky. Given the number of coins and the probab
c79d
ility that the coins come up heads after tossing for each kind, your task is to calculate the probability for each kind of coins that will be lucky.
Input
The first line is the number of test cases. For each test case, the first line contains an integer k representing the number of kinds. Each of the following k lines describes a kind of coins, which contains an integer and a real number representing the number of coins and the probability that the coins come up heads after tossing. It is guaranteed that the number of kinds is no more than 10, the total number of coins is no more than 1000000, and the probabilities that the coins come up heads after tossing are between 0.4 and 0.6.
Output
For each test case, output a line containing k real numbers with the precision of 6 digits, which are the probabilities of each kind of coins that will be lucky.
Sample Input
3
1
1000000 0.5
2
1 0.4
1 0.6
3
2 0.4
2 0.5
2 0.6
Sample Output
1.000000
0.210526 0.473684
0.124867 0.234823 0.420066
概率公式推导:
首先构建一个表,表示100次之内,存活到现在的概率,以及在之前就已经死亡的概率。
对于每一个数,每一个概率相当于是,当前恰好不死*其他全部阵亡的累加和!
Recently, paleoanthropologists have found historical remains on an island in the Atlantic Ocean. The most inspiring thing is that they excavated in a magnificent cave and found that it was a huge tomb. Inside the construction,researchers identified a large number of skeletons, and funeral objects including stone axe, livestock bones and murals. Now, all items have been sorted, and they can be divided into N types. After they were checked attentively, you are told that there are AiAi items of the i-th type. Further more, each item of the i-th type requires BiBi million dollars for transportation, analysis, and preservation averagely. As your job, you need to calculate the total expenditure.
Input
The first line of input contains an integer T which is the number of test cases. For each test case, the first line contains an integer N which is the number of types. In the next N lines, the i-th line contains two numbers AiAi and BiBi as described above. All numbers are positive integers and less than 101.
Output
For each case, output one integer, the total expenditure in million dollars.
Sample Input
1
2
1 2
3 4
Sample Output
14
水题求个乘再累加
#include <iostream> #include <stdio.h> #include <algorithm> #include <math.h> using namespace std; int main() { int T; scanf("%d",&T); while(T--){ int ans=0; int n;scanf("%d",&n); for(int i=1;i<=n;i++){ int a,b;scanf("%d %d",&a,&b); ans+=a*b; } printf("%d\n",ans); } }
B - Pocket Cube
The Pocket Cube, also known as the Mini Cube or the Ice Cube, is the 2 × 2 × 2 equivalence of a Rubik’s Cube.
The cube consists of 8 pieces, all corners.
Each piece is labeled by a three dimensional coordinate (h, k, l) where h, k, l ∈ {0, 1}. Each of the six faces owns four small faces filled with a positive integer.
For each step, you can choose a certain face and turn the face ninety degrees clockwise or counterclockwise.
You should judge that if one can restore the pocket cube in one step. We say a pocket cube has been restored if each face owns four same integers.
Input
The first line of input contains one integer N(N ≤ 30) which is the number of test cases.
For each test case, the first line describes the top face of the pocket cube, which is the common 2 × 2 face of pieces
labelled by (0, 0, 1),(0, 1, 1),(1, 0, 1),(1, 1, 1). Four integers are given corresponding to the above pieces.
The second line describes the front face, the common face of (1, 0, 1),(1, 1, 1),(1, 0, 0),(1, 1, 0). Four integers are
given corresponding to the above pieces.
The third line describes the bottom face, the common face of (1, 0, 0),(1, 1, 0),(0, 0, 0),(0, 1, 0). Four integers are
given corresponding to the above pieces.
The fourth line describes the back face, the common face of (0, 0, 0),(0, 1, 0),(0, 0, 1),(0, 1, 1). Four integers are
given corresponding to the above pieces.
The fifth line describes the left face, the common face of (0, 0, 0),(0, 0, 1),(1, 0, 0),(1, 0, 1). Four integers are given
corresponding to the above pieces.
The six line describes the right face, the common face of (0, 1, 1),(0, 1, 0),(1, 1, 1),(1, 1, 0). Four integers are given
corresponding to the above pieces.
In other words, each test case contains 24 integers a, b, c to x. You can flat the surface to get the surface development
as follows.
+
| q | r | a | b | u | v |
+
| s | t | c | d | w | x |
+
| e | f |
+
| g | h |
+
| i | j |
+
| k | l |
+
| m | n |
+
| o | p |
+
Output
For each test case, output YES if can be restored in one step, otherwise output NO.
Sample Input
4
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6
6 6 6 6
1 1 1 1
2 2 2 2
3 3 3 3
5 5 5 5
4 4 4 4
1 4 1 4
2 1 2 1
3 2 3 2
4 3 4 3
5 5 5 5
6 6 6 6
1 3 1 3
2 4 2 4
3 1 3 1
4 2 4 2
5 5 5 5
6 6 6 6
Sample Output
YES
YES
YES
NO
分析:二阶魔方模拟题,共计六种情况。
坑点:初始化不能为相同值,至今莫名其妙。
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> using namespace std; #define INF 0x3f3f3f3f int a[12][11], b[11][11]; void read() { scanf("%d%d%d%d", &a[1][3], &a[1][4], &a[2][3], &a[2][4]); scanf("%d%d%d%d", &a[3][3], &a[3][4], &a[4][3], &a[4][4]); scanf("%d%d%d%d", &a[5][3], &a[5][4], &a[6][3], &a[6][4]); scanf("%d%d%d%d", &a[7][3], &a[7][4], &a[8][3], &a[8][4]); scanf("%d%d%d%d", &a[1][1], &a[1][2], &a[2][1], &a[2][2]); scanf("%d%d%d%d", &a[1][5], &a[1][6], &a[2][5], &a[2][6]); } int check() { int flag = 1; if (a[1][3] == a[1][4] && a[1][3] == a[2][3] && a[1][3] == a[2][4]) {} else flag = 0; if (a[3][3] == a[3][4] && a[3][3] == a[4][3] && a[3][3] == a[4][4]) {} else flag = 0; if (a[5][3] == a[5][4] && a[5][3] == a[6][3] && a[5][3] == a[6][4]) {} else flag = 0; if (a[7][3] == a[7][4] && a[7][3] == a[8][3] && a[7][3] == a[8][4]) {} else flag = 0; if (a[1][1] == a[1][2] && a[1][1] == a[2][1] && a[1][1] == a[2][2]) {} else flag = 0; if (a[1][5] == a[1][6] && a[1][5] == a[2][5] && a[1][5] == a[2][6]) {} else flag = 0; return flag; } void f() { for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { a[i][j] = b[i][j]; } } } int main() { int n; scanf("%d", &n); while (n--) { //memset(a, 0, sizeof a); for (int i = 0; i < 11; i++) { for (int j = 0; j < 11; j++) { a[i][j] = i*11+j; } } read(); for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { b[i][j] = a[i][j]; } } if (check()) { printf("YES\n"); continue; } f(); int temp = a[1][1]; a[1][1] = a[6][4]; a[6][4] = a[1][5]; a[1][5] = a[1][3]; a[1][3] = temp; temp = a[1][2]; a[1][2] = a[6][3]; a[6][3] = a[1][6]; a[1][6] = a[1][4]; a[1][4] = temp; if (check()) { printf("YES\n"); continue; } f(); temp = a[1][1]; a[1][1] = a[1][3]; a[1][3] = a[1][5]; a[1][5] = a[6][4]; a[6][4] = temp; temp = a[1][2]; a[1][2] = a[1][4]; a[1][4] = a[1][6]; a[1][6] = a[6][3]; a[6][3] = temp; if (check()) { printf("YES\n"); continue; } f(); temp = a[2][3]; a[2][3] = a[4][3]; a[4][3] = a[6][3]; a[6][3] = a[8][3]; a[8][3] = temp; temp = a[1][3]; a[1][3] = a[3][3]; a[3][3] = a[5][3]; a[5][3] = a[7][3]; a[7][3] = temp; if (check()) { printf("YES\n"); continue; } f(); temp = a[2][3]; a[2][3] = a[8][3]; a[8][3] = a[6][3]; a[6][3] = a[4][3]; a[4][3] = temp; temp = a[1][3]; a[1][3] = a[7][3]; a[7][3] = a[5][3]; a[5][3] = a[3][3]; a[3][3] = temp; if (check()) { printf("YES\n"); continue; } f(); temp = a[8][3]; a[8][3] = a[2][2]; a[2][2] = a[3][4]; a[3][4] = a[1][5]; a[1][5] = temp; temp = a[8][4]; a[8][4] = a[1][2]; a[1][2] = a[3][3]; a[3][3] = a[2][5]; a[2][5] = temp; if (check()) { printf("YES\n"); continue; } f(); temp = a[8][3]; a[8][3] = a[1][5]; a[1][5] = a[3][4]; a[3][4] = a[2][2]; a[2][2] = temp; temp = a[8][4]; a[8][4] = a[2][5]; a[2][5] = a[3][3]; a[3][3] = a[1][2]; a[1][2] = temp; if (check()) { printf("YES\n"); continue; } printf("NO\n"); } }
C - Pocky
Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decorative stripes in the coating, of length L.
While the length of remaining pocky is longer than d, we perform the following procedure. We break the pocky at any point on it in an equal possibility and this will divide the remaining pocky into two parts. Take the left part and eat it. When it is not longer than d, we do not repeat this procedure.
Now we want to know the expected number of times we should repeat the procedure above. Round it to 6 decimal places behind the decimal point.
Input
The first line of input contains an integer N which is the number of test cases. Each of the N lines contains two float-numbers L and d respectively with at most 5 decimal places behind the decimal point where 1 ≤ d, L ≤ 150.
Output
For each test case, output the expected number of times rounded to 6 decimal places behind the decimal point in a line.
Sample Input
6
1.0 1.0
2.0 1.0
4.0 1.0
8.0 1.0
16.0 1.0
7.00 3.00
Sample Output
0.000000
1.693147
2.386294
3.079442
3.772589
1.847298
1+lnx的规律
#include <iostream> #include <stdio.h> #include <algorithm> #include <math.h> using namespace std; int main() { int n; double l,d; scanf("%d",&n); while(n--){ scanf("%lf %lf",&l,&d); if(d>=l){ printf("%.6lf\n",0); } else printf("%.6lf\n",1.0+log(l/d)); } }
D - Lucky Coins
Bob has collected a lot of coins in different kinds. He wants to know which kind of coins is lucky. He finds out a lucky kind of coins by the following way. He tosses all the coins simultaneously, and then removes the coins that come up tails. He then tosses all the remaining coins and removes the coins that come up tails. He repeats the previous step until there is one kind of coins remaining or there are no coins remaining. If there is one kind of coins remaining, then this kind of coins is lucky. Given the number of coins and the probab
c79d
ility that the coins come up heads after tossing for each kind, your task is to calculate the probability for each kind of coins that will be lucky.
Input
The first line is the number of test cases. For each test case, the first line contains an integer k representing the number of kinds. Each of the following k lines describes a kind of coins, which contains an integer and a real number representing the number of coins and the probability that the coins come up heads after tossing. It is guaranteed that the number of kinds is no more than 10, the total number of coins is no more than 1000000, and the probabilities that the coins come up heads after tossing are between 0.4 and 0.6.
Output
For each test case, output a line containing k real numbers with the precision of 6 digits, which are the probabilities of each kind of coins that will be lucky.
Sample Input
3
1
1000000 0.5
2
1 0.4
1 0.6
3
2 0.4
2 0.5
2 0.6
Sample Output
1.000000
0.210526 0.473684
0.124867 0.234823 0.420066
概率公式推导:
首先构建一个表,表示100次之内,存活到现在的概率,以及在之前就已经死亡的概率。
对于每一个数,每一个概率相当于是,当前恰好不死*其他全部阵亡的累加和!
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<iomanip> #include<algorithm> using namespace std; const int maxn = 15; const int maxm = 105; double alive[maxn][maxm]; double dead[maxn][maxm]; int num[maxn]; double p[maxn]; double ans[maxn]; double qkm(double a, int k) { double res = 1.0; while (k) { if (k & 1) { res = res*a; } a = a*a; k >>= 1; } return res; } int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &num[i]); scanf("%lf", &p[i]); } if (n == 1) { cout << "1.000000" << endl; continue; } memset(ans, 0, sizeof ans); memset(dead, 0, sizeof dead); memset(alive, 0, sizeof alive); for (int i = 1; i <= n; i++) { for (int j = 1; j <= 100; j++) { dead[i][j] = 1.0-qkm((p[i]), j); dead[i][j] = qkm(dead[i][j], num[i]); alive[i][j] = 1.0 - dead[i][j]; } } for (int i = 1; i <= n; i++) { ans[i] = 0.0; for (int k = 1; k <100; k++) { double tmp = 1.0; for (int j = 1; j <= n; j++) { if (i == j) continue; tmp *= dead[j][k]; } ans[i] += tmp*(alive[i][k] - alive[i][k + 1]); } } for (int i = 1; i <= n; i++) { if (i!=1) cout << " "; printf("%.6f", ans[i]); } cout << endl; } //system("pause"); return 0; }
相关文章推荐
- 【2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A】【模拟 STL-map】Email Aliases 不同邮箱的数量
- 2016 ACM/ICPC 青岛区域赛网络赛 1005 Balanced Game (找规律)
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)H】【迭代 排序 模拟】Hilbert Sort 图形拐拐划分,经过所有点的
- 【HDU5929 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 H】【打表找规律 队列模拟】Basic Data Structure 双端栈下连续1和0做nand的结果
- 【心情】2016ICPC青岛站打铁记
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest A题:Anagrams [打表/规律题]
- 2016ICPC青岛站总结
- 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- 2016 ACM-ICPC Asia Regional Changchun 1002 Fraction(模拟)
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)C】【排序 模拟】Classy 课程难度排序超多关键字
- 2016ACM/ICPC亚洲区青岛站 G - Coding Contest (最小费用最大流)
- 2016ICPC青岛站流水账
- 2016 ICPC青岛站---k题 Finding Hotels(K-D树)
- Codeforces 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A题 (String模拟)
- 2016ACM/ICPC亚洲区青岛站【solved:5 / 13】
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A Email Aliases(模拟STL vector+map)
- 【模拟】NEERC15 A Adjustment Office (2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)(A)(模拟||规律)
- HDU 5976 && 2016ICPC大连 F: Detachment(找规律)
- Codeforces 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest I题(模拟)