洛谷 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;
}

结果:

相关推荐
whxnchy1 小时前
UDP多端口负载均衡实战
c++
叼烟扛炮2 小时前
C++ 知识点08 类与对象
开发语言·c++·算法·类和对象
楼田莉子2 小时前
仿Muduo的高并发服务器:Http协议模块
linux·服务器·c++·后端·学习
tjl521314_219 小时前
04C++ 名称空间(Namespace)
开发语言·c++
ximu_polaris9 小时前
设计模式(C++)-行为型模式-备忘录模式
c++·设计模式·备忘录模式
tankeven13 小时前
C++ 智能指针
c++
handler0116 小时前
【算法模板】最小生成树:稠密图选 Prim,稀疏图选 Kruskal
c语言·数据结构·c++·算法
许长安16 小时前
RPC 异步调用基本使用方法:基于官方helloworld-async 示例
c++·经验分享·笔记·rpc
sparEE16 小时前
c++面向对象:对象的赋值
开发语言·c++
此生决int16 小时前
快速复习之数据结构篇——栈和队列
数据结构·c++