【第16届蓝桥杯软件赛】CB组第一次省赛

打印 上一主题 下一主题

主题 1737|帖子 1737|积分 5211


   个人主页:Guiat
归属专栏:算法竞赛

  


  
正文
   总共10道题。
  A. 移动距离(5分填空题)

【题目】移动距离
【分析】
考察数学。先往右走直线,再走圆弧,即最优解。
【答案】1576
【AC_Code】
  1. #include <bits/stdc++.h>
  2. #define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
  3. using namespace std;
  4. void solve()
  5. {
  6.         int x = 233, y = 666; double r = sqrt(x * x + y * y);
  7.         double res = r * (1 + atan2(y, x));
  8.         cout << fixed << setprecision(0)  << res << '\n';
  9. }
  10. int main()
  11. {
  12.         IOS int _ = 1;   // cin >> _;
  13.         while (_ --) solve();
  14.        
  15.         return 0;
  16. }
复制代码
B. 客流量上限(5分填空题)

【题目】客流量上限
【分析】
【答案】781448427
【AC_Code1】
  1. #include <bits/stdc++.h>
  2. #define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
  3. using namespace std;
  4. using ll = long long;
  5. const int mod = 1e9 + 7;
  6. int FE(int m, int k, int p)
  7. {
  8.         ll t = m, res = 1;
  9.         while (k)
  10.         {
  11.                 if (k & 1) res = res * t % p;
  12.                 k >>= 1; t = t * t % p;
  13.         }
  14.         return res;
  15. }
  16. void solve()
  17. {
  18.         cout << FE(2, 1012, mod) << '\n';
  19. }
  20. int main()
  21. {
  22.         IOS int _ = 1;   // cin >> _;
  23.         while (_ --) solve();
  24.        
  25.         return 0;
  26. }
复制代码
【AC_Code2】
  1. #include <bits/stdc++.h>
  2. #define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
  3. using namespace std;
  4. const int mod = 1e9 + 7;
  5. int pow(int m, int k, int p)
  6. {
  7.         int res = 1;
  8.         while (k --) res = res * m % p;
  9.         return res;
  10. }
  11. void solve()
  12. {
  13.         cout << pow(2, 1012, mod) << '\n';
  14. }
  15. int main()
  16. {
  17.         IOS int _ = 1;   // cin >> _;
  18.         while (_ --) solve();
  19.        
  20.         return 0;
  21. }
复制代码
C. 可分解的正整数

【题目】可分解的正整数
【分析】
考察模拟。根据题意,分析出除1以外的任何整数都可以分解。
【AC_Code】
  1. #include <bits/stdc++.h>
  2. #define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
  3. using namespace std;
  4. const int N = 1e5 + 10; int a[N], ans;
  5. void solve()
  6. {
  7.         int n; cin >> n;
  8.         for (int i = 0; i < n; i ++) { cin >> a[i]; if (a[i] != 1) ans ++; }
  9.         cout << ans << '\n';
  10. }
  11. int main()
  12. {
  13.         IOS int _ = 1;   // cin >> _;
  14.         while (_ --) solve();
  15.        
  16.         return 0;
  17. }
复制代码
D. 产值调整

【题目】产值调整
【分析】
按题意暴力模拟会超时只有30分。“观察到”假如 A, B, C 三个数类似的话再处理还是不改变三个数大小,此时直接跳出循环来节省时间,可以拿到满分。
【AC_Code】
  1. #include <bits/stdc++.h>
  2. #define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
  3. using namespace std;
  4. void solve()
  5. {
  6.         int T; cin >> T;
  7.         while (T --)
  8.         {
  9.                 int A, B, C, K; cin >> A >> B >> C >> K;
  10.                 while (K --)
  11.                 {
  12.                         int a = A, b = B, c = C;
  13.                         A = (b + c) / 2; B = (a + c) / 2; C = (a + b) / 2;
  14.                         if (A == B && B == C) break;   // 拿满分关键
  15.                 }
  16.                 cout << A << ' ' << B << ' ' << C << '\n';
  17.         }
  18. }
  19. int main()
  20. {
  21.         IOS int _ = 1;   // cin >> _;
  22.         while (_ --) solve();
  23.        
  24.         return 0;
  25. }
复制代码
E. 画展布置

【题目】画展布置
【分析】
【AC_Code】
  1. #include <bits/stdc++.h>
  2. #define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
  3. using namespace std;
  4. using ll = long long;
  5. const int N = 1e5 + 10; ll a[N], ans = LLONG_MAX;
  6. void solve()
  7. {
  8.         int n, m; cin >> n >> m;
  9.         for (int i = 0; i < n; i ++) cin >> a[i], a[i] *= a[i];
  10.         sort(a, a + n);
  11.         for (int l = 0, r = m - 1; r < n; l ++, r ++) ans = min(a[r] - a[l], ans);
  12.         cout << ans << '\n';  
  13. }
  14. int main()
  15. {
  16.         IOS int _ = 1;   // cin >> _;
  17.         while (_ --) solve();
  18.        
  19.         return 0;
  20. }
复制代码
F. 水质检测

【题目】水质检测
【分析】
【AC_Code】
  1. #include <bits/stdc++.h>
  2. #define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
  3. using namespace std;
  4. void solve()
  5. {
  6.         string a, b; cin >> a >> b;
  7.         int last = -1, state = -1, cnt = 0;
  8.         for (int i = 0; i < a.length(); i ++)
  9.         {
  10.                 if (a[i] == '.' && b[i] == '.') continue;
  11.                 if (last != -1) cnt += i - last - 1;
  12.                 if (a[i] == '#' && b[i] == '#') state = 3;
  13.                 else if (a[i] == '#' && b[i] == '.')
  14.                 {
  15.                         if (state == 2) { cnt ++; state = 3; } else state = 1;
  16.                 }
  17.                 else if (a[i] == '.' && b[i] == '#')
  18.                 {
  19.                         if (state == 1) { cnt ++; state = 3; } else state = 2;
  20.                 }
  21.                 last = i;
  22.         }
  23.         cout << cnt << '\n';
  24. }
  25. int main()
  26. {
  27.         IOS int _ = 1;   // cin >> _;
  28.         while (_ --) solve();
  29.        
  30.         return 0;
  31. }
复制代码
G. 生产车间

【题目】生产车间
【分析】
【AC_Code】
H. 装修报价

【题目】装修报价
【分析】
【AC_Code1】
  1. #include <bits/stdc++.h>
  2. #define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
  3. using namespace std;
  4. using ll = long long;
  5. const int mod = 1e9 + 7;
  6. int s, ans;
  7. ll FE(ll a, ll b, ll p)
  8. {
  9.         ll ans = 1; a %= p;
  10.         while (b)
  11.         {
  12.                 if (b & 1) ans = (ans * a) % p;
  13.                 b >>= 1; a = (a * a) % p;
  14.         }
  15.         return ans % p;
  16. }
  17. void solve()
  18. {
  19.         int n; cin >> n;
  20.         for (int i = 1; i <= n; i ++)
  21.         {
  22.                 int a; cin >> a; s ^= a;
  23.                 if (i < n) { ans += 2 * s * FE(3ll, n - i - 1, mod) % mod; }
  24.                 else ans += s;
  25.                 ans %= mod;
  26.         }
  27.         cout << ans << '\n';
  28. }
  29. int main()
  30. {
  31.         IOS int _ = 1;   // cin >> _;
  32.         while (_ --) solve();
  33.        
  34.         return 0;
  35. }
复制代码
【AC_Code2】
  1. #include <bits/stdc++.h>
  2. #define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
  3. using namespace std;
  4. using ll = long long;
  5. const int mod = 1e9 + 7; ll sum, ans;
  6. void solve()
  7. {
  8.         int n; cin >> n;
  9.         for (int i = 1; i <= n; i ++)
  10.         {
  11.                 int a; cin >> a;
  12.                 ans = (ans * 3 - sum + (sum ^= a) + mod) % mod;
  13.         }
  14.         cout << ans << '\n';
  15. }
  16. int main()
  17. {
  18.         IOS int _ = 1;   // cin >> _;
  19.         while (_ --) solve();
  20.        
  21.         return 0;
  22. }
复制代码
结语
感谢您的阅读!等候您的一键三连!接待指正!


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

千千梦丶琪

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表