AtCoder Beginner Contest 114 Solution
阿新 • • 發佈:2018-12-02
Solved.
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int mp[10]; 5 6 int main() 7 { 8 mp[7] = mp[5] = mp[3] = 1; 9 int x; cin >> x; 10 puts(mp[x] ? "YES" : "NO"); 11 }View Code
Solved.
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 char s[20]; 5 6 int f(int x) 7 { 8 int res = 0; 9 for (int i = 0; i < 3; ++i) res = res * 10 + s[i + x] - '0'; 10 return res; 11 } 12 13 intView Codemain() 14 { 15 while (scanf("%s", s + 1) != EOF) 16 { 17 int res = 0x3f3f3f3f, len = strlen(s + 1); 18 for (int i = 1; i <= len - 2; ++i) res = min(res, abs(f(i) - 753)); 19 printf("%d\n", res); 20 } 21 return 0; 22 }
Solved.
題意:
找出$[1, n]中有多少個只由'7', '5', '3' 組成,並且每個字元至少出現一次的數$
思路:
這樣的數不會太多,DFS構造,然後二分
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 vector <int> v; 5 6 bool ok(int x) 7 { 8 int flag[10] = {false}; 9 while (x) 10 { 11 flag[x % 10] = 1; 12 x /= 10; 13 } 14 if (flag[3] == 0 || flag[5] == 0 || flag[7] == 0) return false; 15 return true; 16 } 17 18 void DFS(int cur, int num) 19 { 20 if (cur == 10) 21 { 22 if (ok(num)) v.push_back(num); 23 return; 24 } 25 DFS(cur + 1, num); 26 DFS(cur + 1, num * 10 + 3); 27 DFS(cur + 1, num * 10 + 5); 28 DFS(cur + 1, num * 10 + 7); 29 } 30 31 int main() 32 { 33 DFS(0, 0); 34 sort(v.begin(), v.end()); 35 v.erase(unique(v.begin(), v.end()), v.end()); 36 int n; 37 while (scanf("%d", &n) != EOF) printf("%d\n", (int)(upper_bound(v.begin(), v.end(), n) - v.begin())); 38 return 0; 39 }View Code
Upsolved.
題意:
有$N!中所有因子中,有多少因子其擁有的因子個數恰好為75個$
思路:
我們考慮$75 = 75 \cdot 1 = 25 \cdot 3 = 15 \cdot 5 = 5 \cdot 5 \cdot 3$
那麼我們處理出$N!中每個質因子一共有多少個,然後考慮質因子個數如何組成因子個數$
考慮一個數$x = a_1^{p_1} \cdot a_2^{p_2} \cdot a_3^{p_3}$
那麼$a_1 可以提供的因子個數為 (p_1 + 1) 那麼x 的因子個數即 (p_1 \cdot p_2 \cdot p_3)$
然後簡單組合一下就可以了
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int n; 5 int cnt[110]; 6 int tot[2100]; 7 8 int f(int l, int r) 9 { 10 int res = 0; 11 for (int i = l; i <= r; ++i) res += tot[i]; 12 return res; 13 } 14 15 int main() 16 { 17 while (scanf("%d", &n) != EOF) 18 { 19 memset(cnt, 0, sizeof cnt); 20 memset(tot, 0, sizeof tot); 21 for (int i = 2; i <= n; ++i) 22 { 23 int tmp = i; 24 for(int j = 2; ; ++j) 25 { 26 while (tmp % j == 0) 27 { 28 ++cnt[j]; 29 tmp /= j; 30 } 31 if (tmp == 1) break; 32 } 33 } 34 for (int i = 2; i <= 100; ++i) ++tot[cnt[i] + 1]; 35 int res = f(75, 2000); 36 res += f(25, 2000) * f(3, 24); 37 res += f(25, 2000) * (f(25, 2000) - 1); 38 res += f(15, 2000) * f(5, 14); 39 res += f(15, 2000) * (f(15, 2000) - 1); 40 res += (f(5, 2000) * (f(5, 2000) - 1) / 2) * f(3, 4); 41 res += ((f(5, 2000) * (f(5, 2000) - 1) / 2) * (f(5, 2000) - 2)); 42 printf("%d\n", res); 43 } 44 return 0; 45 }View Code