AtCoder Beginner Contest 114 Solution

A 753

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     }

B 754

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     int main()
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     }

C 755

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     }

D 756

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         }

原文地址:https://www.cnblogs.com/Dup4/p/10055835.html

时间: 2024-11-03 11:49:08

AtCoder Beginner Contest 114 Solution的相关文章

AtCoder Beginner Contest 115 Solution

A Christmas Eve Eve Eve Solved. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int main() 5 { 6 int n; 7 8 while (scanf("%d", &n) != EOF) 9 { 10 printf("Christmas"); 11 int need = 3 - (n - 22); 12 for (int i = need; i;

AtCoder Beginner Contest 154 题解

人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one

AtCoder Beginner Contest 103 D(贪心)

AtCoder Beginner Contest 103 D 题目大意:n个点,除第n个点外第i与第i+1个点有一条边,给定m个a[i],b[i],求最少去掉几条边能使所有a[i],b[i]不相连. 按右端点从小到大排序,如果当前选的去掉的边在区间内,那么符合条件,否则ans++,并贪心地把去掉的边指向右端点,因为前面的区间都满足条件了,所以要去掉的边要尽量向右移使其满足更多的区间. 1 #include <iostream> 2 #include <cstdio> 3 #incl

AtCoder Beginner Contest 136

AtCoder Beginner Contest 136 Contest Duration : 2019-08-04(Sun) 20:00 ~ 2019-08-04(Sun) 21:40 Website: AtCoder BC-136 后面几题都挺考思考角度D. C - Build Stairs 题目描述: 有n座山从左到右排列,给定每一座山的高度\(Hi\),现在你可以对每座山进行如下操作至多一次:将这座山的高度降低1. 问是否有可能通过对一些山进行如上操作,使得最后从左至右,山的高度呈不下降

AtCoder Beginner Contest 155 简要题解

AtCoder Beginner Contest 155 A:签到失败,WA一次. int main() { int a, b, c; cin >> a >> b >> c; if(a == b && b == c) cout << "No"; else if(a == b || a == c || b == c) cout << "Yes"; else cout << &quo

AtCoder Beginner Contest 152 - F - Tree and Constraints (容斥定理+树上路径的性质)

AtCoder Beginner Contest 152 - F - Tree and Constraints (容斥定理+树上路径的性质) We have a tree with NN vertices numbered 11 to NN. The ii-th edge in this tree connects Vertex aiai and Vertex bibi. Consider painting each of these edges white or black. There ar

【ATcoder】AtCoder Beginner Contest 161 题解

题目链接:AtCoder Beginner Contest 161 原版题解链接:传送门 A - ABC Swap 这题太水,直接模拟即可. 1 #include <iostream> 2 using namespace std; 3 int main() { 4 int a, b, c; 5 cin >> a >> b >> c; 6 swap(a, b); 7 swap(a, c); 8 cout << a << " &

AtCoder Beginner Contest 115 题解

题目链接:https://abc115.contest.atcoder.jp/ A Christmas Eve Eve Eve 题目: Time limit : 2sec / Memory limit : 1024MB Score : 100 points Problem Statement In some other world, today is December D-th. Write a program that prints Christmas if D=25, Christmas E

AtCoder Beginner Contest 106 ABCD

A - Garden Problem Statement There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents