洛谷 P1328 [NOIP2014 提高组] 生活大爆炸版石头剪刀布

题解:

cpp 复制代码
#include<iostream>
#include<vector>
//定义二维数组,直接标识不同出法相应对应关系
int mark[5][5]={{0,-1,1,1,-1},{1,0,-1,1,-1},{-1,1,0,-1,1},{-1,-1,1,0,1},{1,1,-1,-1,0}};
void JudgeScore(int A,int B,int& countA,int& countB){
    if(mark[A][B]==1) countA++;
    else if(mark[A][B]==-1) countB++;
}
int main(){
    int N,NA,NB,countA=0,countB=0;
    std::cin>>N>>NA>>NB;
    std::vector<int> A(NA),B(NB);
    for(int i=0;i!=NA;++i) std::cin>>A[i];
    for(int i=0;i!=NB;++i) std::cin>>B[i];
    int i=0,j=0;
    while(N--){
        JudgeScore(A[i],B[j],countA,countB);
        i=(i+1)%NA,j=(j+1)%NB;
        //每次下标移动到数组结尾时从零开始,本质就是取模运算的过程
    }
    std::cout<<countA<<" "<<countB;
    return 0;
}

结果:

相关推荐
stolentime20 分钟前
洛谷P10515 转圈题解
c++·算法·数学建模·贪心算法
tdtsmt1 小时前
穿戴硬件量产工艺实录:天地通电子智能手表主板 SMT 贴片案
c++
m0_734571765 小时前
深入理解C++ 析构函数<一>基本概念
开发语言·c++
t-think6 小时前
C++ string 类(上)—— string类初识与常用接口详解
开发语言·c++
cpp_learners6 小时前
C++ 实现责任链模式(Chain of Responsibility):从一堆 if-else 到可插拔的处理管道
开发语言·c++·责任链模式
郝学胜_神的一滴6 小时前
C++11 工程级应用 12:编译期类型魔法,干掉重复与臃肿的代码
c++·visual studio
David猪大卫7 小时前
【C++修炼】哈希表的实现
数据结构·c++·笔记·学习·算法·哈希算法·散列表
广州山泉婚姻7 小时前
列表初始化:C++11全新初始化体系
c++·人工智能
莫生灬灬8 小时前
灵码 LingBuilder:用中文写代码,确定性生成真实 C++ 工程(开源)
c++·开源·mfc
浅念-8 小时前
C++ Protobuf 入门实战:基于通讯录项目吃透proto3语法与序列化
linux·服务器·网络·c++·protobuf·proto·proto3