This dish mistaken the time and failed to catch up with t_t. This question does not seem very simple. Today I have made a general introduction.
250pt: Water question
550pt: Give A, B, X, and ask for Y, so that all values of a * P + B * Q can be obtained through X * p '+ y * Q. Return-1 if there are infinite possibilities. Return-1 when X is divisible by A and B at the same time. Y is enumerated in other cases and Y is satisfied (a-y * Q ') % x = 0 and (B-x * p') % Y = 0.
View code
1 #include <vector>
2 #include <list>
3 #include <map>
4 #include <set>
5 #include <queue>
6 #include <deque>
7 #include <stack>
8 #include <bitset>
9 #include <algorithm>
10 #include <functional>
11 #include <numeric>
12 #include <utility>
13 #include <sstream>
14 #include <iostream>
15 #include <iomanip>
16 #include <cstdio>
17 #include <cmath>
18 #include <cstdlib>
19 #include <ctime>
20
21 using namespace std;
22
23
24 class KingXNewCurrency {
25 public:
26 int howMany(int A, int B, int X) {
27 int cnt = 0, f;
28 int y, k;
29
30 if(!(A%X) && !(B%X)) return -1;
31 int M = max(A, B);
32 for(y = 1; y <= M; ++y) {
33 f = 0;
34 for(k = 0; k <= A; k += y) {
35 if((A - k)%X == 0) {
36 f++; break;
37 }
38 }
39 for(k = 0; k <= B; k += X) {
40 if((B-k)%y == 0) {
41 f++; break;
42 }
43 }
44 if(f == 2) cnt++;
45 }
46 return cnt;
47 }
48 };
49
50
51 <%:testing-code%>
52 //Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
925pt:
I did not understand the ideas of the experts.
03/22 supplement:
925pt:
I read polla's solution report... I want to understand.
The probability of a cake with a value of-1 being absorbed is 1. If a sequence a-> B-> C-> D exists, it can be seen that a, B, C has a total of 33 cases, but only one case is that D can be absorbed. Therefore, the probability that D is absorbed is 1/a 33.
The final result can accumulate the probability of all elements.
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class PrinceXToastbook {
public:
double eat(vector <int> pre) {
double res = 0, tmp;
int i, j, r, m;
int l = pre.size();
for(i = 0; i < l; ++i) {
r = i; m = 1;
while(m < 55) {
r = pre[r];
if(r == -1) break;
++m;
}
tmp = 1.0;
for(j = 1; j <= m; ++j) {
tmp *= j;
}
res += 1.0/tmp;
}
return res;
}
};
<%:testing-code%>
//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!