2023河南萌新联赛第(四)场

news/发布时间2024/5/9 16:24:17

B. 序列的与和(二进制搜索)

输入

3 6
2 4 1

输出

0

说明

对于样例,其子序列有:
[2]:其与和为10(二进制),仅包含一个1,不为6,所以对答案贡献为零
[2,4]:与和为 0 ,同理,贡献为零。
[2,1]:与和结果0
[2,4,1]:与和结果0
[4]:与和结果100
[4,1]:与和结果0
[1]:与和结果1
综上,答案为0。

点击查看代码
#include<bits/stdc++.h>
#define ull unsigned long longusing namespace std;int check(ull x)
{int ans = 0;while(x){if(x & 1) ans ++;x >>= 1;}return ans;
}int main()
{int n, k, ans = 0;cin >> n >> k;vector<int> a(n);for(auto &x : a)cin >> x;for(int i = 0; i < 1 << n; i ++){ull s = (1ull << 64) - 1;for(int j = 0; j < n; j ++)if(i >> j & 1) s &= a[j];if(check(s) == k) ans ++;}cout << ans << "\n";return 0;
}

D. 幂运算(高精度+欧拉函数)

输入

3 1223

输出

256

点击查看代码
#include<bits/stdc++.h>
#define int long longusing namespace std;int qmi(int a, int b, int mod)
{int ans = 1;while(b){if(b & 1) ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans;
}int get(int x)
{int ans = x;for(int i = 2; i < x / i; i ++){if(x % i == 0){ans = ans / i * (i - 1);while(x % i == 0)x /= i;}}if(x > 1)ans = ans / x * (x - 1);return ans;
}void solve()
{int n, m, p;cin >> n >> p;int ans = 2;for(int i = 1; i <= n; i ++)ans = ans * ans % p;cout << ans << "\n";
}signed main()
{ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);int T = 1;while(T --)solve();return T ^ T;
}

J. 异次元抓捕(博弈)

输入1

2
1
617

输出1

YES
NO

说明

k=1的时候
黑色代表障碍 红色是行动轨迹 蓝色是每次移动可以走的位置 (不是最佳方案,仅供理解用)(解释仅供说明移动方式和摆放障碍的方式)

输入2

1
17

输出2

NO

点击查看代码
#include<bits/stdc++.h>using namespace std;void solve()
{int n, m;cin >> n;m = n - 1;if(n == 1) puts("YES");else puts("NO");
}signed main()
{ios::sync_with_stdio(false);cin.tie(0);int T = 1;cin >> T;while(T --)solve();return T ^ T;
}

K. 奖励关(贪心)

输入

2
1
3

输出

1
2

说明

当前攻击力等于 2i+3xj, i表示已执行操作2的次数 ,j表示当前攻击与上一次攻击间隔间的操作3的次数

点击查看代码
#include<bits/stdc++.h>
#define int long longusing namespace std;const int N = 110;int a[N], ans[N];
/*
2 4 8 16 32 64 128 256 512 1024 2048
4096 8192 16384 32768 65536 131072 262144
524288 1048576 2097152 4194304 8388608 16777216
33554432 67108864 134217728 268435456 536870912
1073741824 2147483648 4294967296 8589934592 17179869184 34359738368
*/void solve()
{int n, m = 1, s = 1, ans = 0;cin >> n;ans = 1;n --;ans += n / 2;cout << ans << "\n";
}signed main()
{ios::sync_with_stdio(false);cin.tie(0);int T = 1;cin >> T;while(T --)solve();return T ^ T;
}

M. 找孙子(dfs枚举)

输入

5 10
5 3
2 3
1 2
4 1
1 3
4 2
2 5
4 3
1 5
4 5

输出

3 1 0 6 0

说明

点击查看代码
#include<bits/stdc++.h>
#define int long longusing namespace std;void solve()
{int n, m, a, b;cin >> n >> m;vector<int> g[n + 1], ans(n + 1);for(int i = 1; i <= m; i ++){cin >> a >> b;g[a].push_back(b);
//         g[b].push_back(a);}for(int i = 1; i <= n; i ++){int t = g[i].size(), s = 0;for(auto x : g[i]){if(x != i)s += g[x].size();
//             s += t;}ans[i] = s;}for(int i = 1; i <= n; i ++)cout << ans[i] << ' ';
}signed main()
{ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);int T = 1;while(T --)solve();return T ^ T;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ulsteruni.cn/article/12722303.html

如若内容造成侵权/违法违规/事实不符,请联系编程大学网进行投诉反馈email:xxxxxxxx@qq.com,一经查实,立即删除!

相关文章

Python 结合opencv实现图片截取和拼接

实践环境 python 3.6.2 scikit-build-0.16.7 win10 opencv_python-4.5.4.60-cp36-cp36m-win_amd64.whl 下载地址: https://pypi.org/project/opencv-python/4.5.4.60/#files https://files.pythonhosted.org/packages/57/6c/7f4f56b2555d5c25dd4f41fc72a16dc6402cb2b4f967da11…

20211301 学习笔记3

20211301《Unix/Linux系统编程》学习笔记3 学习目标总结一下一门程序设计语言有哪些必备的要素和技能?这些要素和技能在shell脚本中是如果呈现出来的?教材知识总结 10.1 sh脚本定义:sh脚本是一个包含sh语句的文本文件、命令解释程序sh要执行该语句sh:sh是解释程序,逐行读取…

嵌入式软件调试与验证2仿真

2 仿真环境中的嵌入式软件调试 2.1 固件调试方法概述 目前的EDA环境提供了各种固件调试方法。通常可以使用以下方法之一:使用硬件的SystemC模型进行仿真这可以在不接触硬件的情况下尽早开始固件开发,并在假设模型准确的情况下测试代码的功能。主要局限是缺乏系统视图和(取决…

webstorm插件分享

插件修改选中区域背景本文来自博客园,作者:__username,转载请注明原文链接:https://www.cnblogs.com/code3/p/17726441.html

Git

目录Git安装初始化配置创建版本库添加文件提交文件时光穿梭版本回退工作区与版本库管理修改撤销修改删除文件远程仓库添加远程库从远程库克隆分支管理解决冲突分支管理策略Bug分支Feature分支多人协作Rebase标签管理创建标签操作标签自定义 Git忽略特殊文件配置别名搭建 Git 服…