2021蓝桥杯B组(没参加比赛, 小白随便写写)

 

A题

#include <iostream>
using namespace std;

int main ()
{
  cout << 256 * 1024 * 1024 / 4 <<endl;

  return 0;
}

 

答案:67108864

B题

 1 #include <iostream>
 2 using namespace std;
 3 
 4 int main ()
 5 {
 6     int a[10] = {2021,2021,2021,2021,2021,2021,2021,2021,2021,2021};
 7     
 8     int res = 0;
 9     int i = 1;
10     while (i)
11     {
12         int k = i;
13         while (k)
14         {
15             if (a[k%10] == 0)
16             {
17                 cout << res <<endl;
18                 return 0;
19             }
20             a[k % 10] -- ;
21             k /= 10;
22 
23         }
24             res++;
25             i ++;
26     }
27     
28     return 0;
29 }

 

答案:3181

C题

 1 #include <iostream>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <cmath>
 5 
 6 using namespace std;
 7 
 8 const int N = 200000;
 9 
10 int n;
11 struct Line
12 {
13     double k, b;
14     bool operator< (const Line& t) const
15     {
16         if (k != t.k) return k < t.k;
17         return b < t.b;
18     }
19 }l[N];
20 
21 int main()
22 {
23     for (int x1 = 0; x1 < 20; x1 ++ )
24         for (int y1 = 0; y1 < 21; y1 ++ )
25             for (int x2 = 0; x2 < 20; x2 ++ )
26                 for (int y2 = 0; y2 < 21; y2 ++ )
27                     if (x1 != x2)
28                     {
29                         double k = (double)(y2 - y1) / (x2 - x1);
30                         double b = y1 - k * x1;
31                         l[n ++ ] = {k, b};
32                     }
33 
34     sort(l, l + n);
35     int res = 1;
36     for (int i = 1; i < n; i ++ )
37         if (fabs(l[i].k - l[i - 1].k) > 1e-8 || fabs(l[i].b - l[i - 1].b) > 1e-8)
38             res ++ ;
39     cout << res + 20 << endl;
40 
41     return 0;
42 }

 

答案:40257

D题

 1 #include <iostream>
 2 #include <vector>
 3 using namespace std;
 4 const int N = 1000010;
 5 vector<long long> q;
 6 
 7 int main ()
 8 {
 9     int res = 0;
10     long long n = 2021041820210418;
11     
12     for (long long i = 1 ; i * i <= n ; i ++ )
13     {
14         if (n % i == 0)
15         {
16             q.push_back(i);
17             if (n / i != i ) q.push_back(n / i);
18         }
19     }
20     
21     for (int a = 0 ; a < q.size() ; a++ )
22         for (int b = 0 ; b < q.size() ; b ++ )
23             for (int c = 0 ; c < q.size() ; c ++)
24                 {
25                     if (q[a] * q[b] * q[c] == n)
26                     res++;
27                 }
28                 
29                 cout << res <<endl;
30                 return 0;
31 }

 

答案:2430

E题(参考yxc)

 1 #include <iostream>
 2 #include <cstring>
 3 #include <algorithm>
 4 
 5 using namespace std;
 6 
 7 const int N = 2200, M = N * 50;
 8 
 9 int n;
10 int h[N], e[M], w[M], ne[M], idx;
11 int q[N], dist[N];
12 bool st[N];
13 
14 int gcd(int a, int b)  // 欧几里得算法
15 {
16     return b ? gcd(b, a % b) : a;
17 }
18 
19 void add(int a, int b, int c)  // 添加一条边a->b,边权为c
20 {
21     e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
22 }
23 
24 void spfa()  // 求1号点到n号点的最短路距离
25 {
26     int hh = 0, tt = 0;
27     memset(dist, 0x3f, sizeof dist);
28     dist[1] = 0;
29     q[tt ++ ] = 1;
30     st[1] = true;
31 
32     while (hh != tt)
33     {
34         int t = q[hh ++ ];
35         if (hh == N) hh = 0;
36         st[t] = false;
37 
38         for (int i = h[t]; i != -1; i = ne[i])
39         {
40             int j = e[i];
41             if (dist[j] > dist[t] + w[i])
42             {
43                 dist[j] = dist[t] + w[i];
44                 if (!st[j])     // 如果队列中已存在j,则不需要将j重复插入
45                 {
46                     q[tt ++ ] = j;
47                     if (tt == N) tt = 0;
48                     st[j] = true;
49                 }
50             }
51         }
52     }
53 }
54 
55 
56 int main()
57 {
58     n = 2021;
59     memset(h, -1, sizeof h);
60     for (int i = 1; i <= n; i ++ )
61         for (int j = max(1, i - 21); j <= min(n, i + 21); j ++ )
62         {
63             int d = gcd(i, j);
64             add(i, j, i * j / d);
65         }
66 
67     spfa();
68     printf("%d\n", dist[n]);
69     return 0;
70 }

 

答案:10266837

F题

#include <iostream>

using namespace std;

typedef long long LL;

int main()
{
    LL n;
    cin >> n;
    n /= 1000;
    n %= 86400;
    int h = n / 3600;
    n %= 3600;
    int m = n / 60;
    int s = n % 60;
    printf("%02d:%02d:%02d\n", h, m, s);
    return 0;
}

 

上一篇:TT语音线程优化,深入讲解Android


下一篇:挑战程序设计竞赛 第十二章 图