热身赛
Time Limit: 1 Second Memory Limit: 65536 KB
Helianthuswolf Co. Ltd. is a multinational “Intestnet” company. Its revenue from global markets grew year by year. Helianthuswolf unveiled its new smartphone Q10 in the spring of 2017.
As a high-end smartphone, Q10 uses UFS2.1 or UFS2.0 or eMMC5.1 for its flash drive. Q10 also uses LPDDR3 or LPDDR4 as its memory, and its CPU does not support DDR3. In order to better show the performance of the Q10, Helianthuswolf reduced the oleophobic coating layer of some smartphones.
Helianthuswolf produces Q10 in two factories. As you see in the following table, the probabilities of the components they use are different. And the use of each component is an independent event.
Flash Drive Memory Oleophobic Layer
UFS2.0 UFS2.1 eMMC5.1 LPDDR3 LPDDR4 Sparse Normal
A 20% 30% 50% 40% 60% 70% 30%
B 30% 50% 20% 70% 30% 40% 60%
Now we get the information of Q10 smartphones produced by one factory. The smartphones are all produced by either factory A or factory B. Please find out which factory is more likely to produce these smartphones.
Input
There are multiple test cases. The first line of the input contains an integer (), indicating the number of test cases. For each test case:
The first line is an integer (), indicating the number of smartphones.
The following lines are the information of the smartphones, each line has three words describing the components.
Output
For each test case, output “A” (without quotes) if it is more likely for factory A to produce these smartphones, output “B” (without quotes) if it is more likely for factory B to produce these smartphones. If it is equally likely for the two factories to produce these smartphones, output “E” (without quotes).
Sample Input
3
1
eMMC5.1 LPDDR4 Sparse
2
UFS2.1 LPDDR3 Sparse
UFS2.0 LPDDR4 Normal
3
UFS2.1 LPDDR3 Sparse
eMMC5.1 LPDDR4 Normal
UFS2.0 LPDDR4 Normal
Sample Output
A
B
E
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <string> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #define INF 0x3f3f3f3f #define EPS 0.00000001 #define lowbit(x) (x&(-x)) using namespace std; typedef long long ll; char a1[3][10] = {"UFS2.0","UFS2.1","eMMC5.1"}; char a2[2][10] = {"LPDDR3","LPDDR4"}; char a3[2][10] = {"Sparse","Normal"}; double r1[2][3] = {{2,3,5},{3,5,2}}; double r2[2][2] = {{4,6},{7,3}}; double r3[2][2] = {{7,3},{4,6}}; int main() { int T; scanf("%d",&T); while(T--) { int n; char s1[10],s2[10],s3[10]; double ans1 = 0, ans2 = 0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%s%s%s",s1,s2,s3); for(int i=0;i<3;i++) if(strcmp(s1,a1[i]) == 0) { ans1 += log(r1[0][i]); ans2 += log(r1[1][i]); break; } for(int i=0;i<2;i++) if(strcmp(s2,a2[i]) == 0) { ans1 += log(r2[0][i]); ans2 += log(r2[1][i]); break; } for(int i=0;i<2;i++) if(strcmp(s3,a3[i]) == 0) { ans1 += log(r3[0][i]); ans2 += log(r3[1][i]); break; } } if(abs(ans1 - ans2) <= EPS) printf("E "); else if(ans1 < ans2) printf("B "); else printf("A "); } }
Time Limit: 2 Seconds Memory Limit: 65536 KB 17171771 is a sweet
17171771 is a sweet song in Jaurim's 5th album, "All You Need Is Love", released in October 2004.
What's the meaning of 17171771? If we rotate it by 180 degrees, it looks like "ILLILILI". If we add some blanks into it, it becomes "I LLILI LI". Doesn't it look like "I LUV U"? The meaning of 17171771 is "I LUV U". Anyway, it has nothing to do with our problem.
What we are concerned more about is that, 17171771 is a prime consisting only of digits 1 and 7 occurring with equal frequency. In this problem, a prime consisting only of two different digits occurring with equal frequency is called nice number. For example, 89, 71717117 and 23323333222223 are nice numbers.
Your task is to print all the nice numbers which are strictly less than 1018
Input
There is no input for this problem.
Output
Output all the nice number less than 1018 in increasing order. The output looks like the following:
13 17 19 ... 17171771 ...
AC代码:
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <string> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #define INF 0x3f3f3f3f #define lowbit(x) (x&(-x)) typedef long long ll; using namespace std; vector <ll> vi; set <ll> st; void dfs(int *a,int len) { do{ ll tp = 0; if(a[0] == 0) continue; for(int i=0;i<len;i++) tp = tp * 10 + a[i]; vi.push_back(tp); }while(next_permutation(a, a + len)); } ll prime[6] = {2, 3, 5, 233, 331}; ll qmul(ll x, ll y, ll mod) // 乘法防止溢出, 如果p * p不爆ll的话可以直接乘; O(1)乘法或者转化成二进制加法 { return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod; } ll qpow(ll a, ll n, ll mod) { ll ret = 1; while(n) { if(n & 1) ret = qmul(ret, a, mod); a = qmul(a, a, mod); n >>= 1; } return ret; } bool Miller_Rabin(ll p) { if(p < 2) return 0; if(p != 2 && p % 2 == 0) return 0; ll s = p - 1; while(! (s & 1)) s >>= 1; for(int i = 0; i < 5; ++i) { if(p == prime[i]) return 1; ll t = s, m = qpow(prime[i], s, p); while(t != p - 1 && m != 1 && m != p - 1) { m = qmul(m, m, p); t <<= 1; } if(m != p - 1 && !(t & 1)) return 0; } return 1; } int main() { int a[20] = {0}; for(int i=0;i<=9;i++) for(int j=i+1;j<=9;j++) for(int k=1;k<=8;k++) { for(int l=0;l<k;l++) { a[l] = i; a[l+k] = j; } dfs(a, k*2); } for(int i=0;i<vi.size();i++) if(Miller_Rabin(vi[i])) st.insert(vi[i]); int cnt = 0; for(set<ll>::iterator it = st.begin(); it != st.end(); it++) { printf("%lld ",(*it)); cnt ++; } cout << cnt << endl; }