当前位置:网站首页>【小码匠自习室】 [NOI Online 2022 入门组] 王国比赛
【小码匠自习室】 [NOI Online 2022 入门组] 王国比赛
2022-08-08 13:52:00 【小码匠】
碎碎念
- 这道题是3月份参赛时做出来的唯一一道题,相对简单。 其实第二道题:数学游戏也是有机会做出来,大意失荆州,当时仔细点,也说不定就AC2道题,伤心的往事...
题目地址
- [NOI Online 2022 入门组] 王国比赛
- https://www.luogu.com.cn/problem/P8254
题目描述
智慧之王 Kri 统治着一座王国。
这天 Kri 决定举行一场比赛,来检验自己大臣的智慧。
比赛由 n 道判断题组成,有 m 位大臣参加。现在你已经知道了所有大臣的答题情况,但尚未拿到答案,于是你决定先行预测。
具体来说,对于第 i 道题,有 x 个大臣选对,y 个大臣选错(显然有 x+y=m),如果 x>y,那么你预测这题答案为对,否则为错。为了方便,我们保证 m 是奇数。
在统计完成后,你拿到了答案,你想知道通过你的预测方式你最后有几道题预测正确。
输入格式
第一行两个正整数 n,m,保证 m 是奇数。
接下来 m 行,每行 n 个整数,第 i 行第 j 个整数代表第 i 位大臣对第 j 道题的答案,1 表示他选对,0 表示他选错。
接下来 1 行 n 个整数, 表示比赛答案,第 i 个数 b_i 若为 1 表示第 i 道题答案是对,若为 0 表示答案是错。
输出格式
输出一个整数,表示你最后有几题预测正确。
输入输出样例
输入 #1
3 3
1 0 1
0 1 1
0 1 0
1 1 1
输出 #1
2
输入 #2
6 5
1 0 1 1 1 0
0 1 0 1 1 1
0 0 1 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
1 0 1 0 1 0
输出 #2
4
输入 #3
见附件中的 kingdom3.in
输出 #3
见附件中的 kingdom3.out
说明/提示
【样例 1 解释】
- 第一题 x=1,y=2 你预测答案为错(即 0),实际答案为1,预测错误。
- 第二题 x=2,y=1 你预测答案为对(即 1),实际答案为1,预测正确。
- 第三题 x=2,y=1 你预测答案为对(即 1),实际答案为1,预测正确。
所以预测正确的题数为 2。
【数据范围】
对于 20% 的数据,n≤5,m=1。
对于 50% 的数据,n≤10,m≤10。
对于 100% 的数据,1≤n≤1000,1≤m≤1000,m 为奇数。
题解
小码匠题解一
- 一次AC
#include <iostream>
#include <cstdio>
using namespace std;
#define endl '\n';
int main() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
int true_false[m + 1][n];
for (int i = 0; i <= m; i++) {
for (int j = 0; j < n; j++) {
cin >> true_false[i][j];
}
}
int true_num = 0;
int false_num = 0;
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (true_false[j][i] == 0) {
false_num++;
} else if (true_false[j][i] == 1) {
true_num++;
}
}
if (false_num > true_num && true_false[m][i] == 0) {
count++;
} else if (false_num < true_num && true_false[m][i] == 1) {
count++;
}
true_num = 0;
false_num = 0;
}
cout << count;
return 0;
}
边栏推荐
猜你喜欢
![[Redis] Bitmap and usage scenarios of bitmap (statistics of online people and user online status)](/img/33/576e4a7c5d5997a9ca639e125708d6.png)
[Redis] Bitmap and usage scenarios of bitmap (statistics of online people and user online status)

干货满满,中科院信工所于静新课帮你get学术研究与论文写作技能

sample function—R language

非科班毕业生,五面阿里:四轮技术面+HR一面已拿offer

QWebAssembly中文适配

Thesis understanding: "Self-adaptive loss balanced Physics-informed neural networks"

KD-SCFNet: More Accurate and Efficient Salient Object Detection Through Knowledge Distillation (ECCV2022)

pip install xxx 出现 AttributeError: ‘tuple’ object has no attribute ‘read’ 错误

难产的“第一股”:中式快餐之困

年初离职,学习半年源码,终于拿到了蚂蚁Offer,分享面试过程
随机推荐
HackTheBox | Horizontall
用 Antlr 重构脚本解释器
MapStruct入门使用
【黑马早报】巴菲特罕见巨亏近3000亿;周鸿祎回应360不能卸载;三亚倡议酒店不变相提高房价;首个国产抗新冠口服药定价不超300元...
mysql 查询一个字段为特定值,并且另一个字段的值出现两次的记录?
Thesis understanding: "Self-adaptive loss balanced Physics-informed neural networks"
优刻得“失速”:营收转降,定向增发股东浮亏超三成
腾讯,投了个 “离诺贝尔奖最近的华人”
使用.NET简单实现一个Redis的高性能克隆版(三)
itk中生成drr整理
【Rust—LeetCode题解】1408.数组中的字符串匹配
Full of dry goods, Yu Jingxin class of the Institute of Information Technology, Chinese Academy of Sciences will help you get academic research and thesis writing skills
Flink1.15 组件RPC通信过程概览图
Knowledge points and written test questions related to shift operations, bit operations, and logical operations
剑指 Offer 66. 构建乘积数组
PostgreSQL 用户与schema有什么区别?
又一个千亿市场,冰淇淋也成了创新试验田
清华|GLM-130B:一个开放的双语预训练模型
2022年8月7日 暑假第四周总结
R语言ggplot2可视化:使用ggpubr包的ggline函数可视化折线图(点线图、line plot)、设置add参数为mean可视化不同水平均值的折线图