340 - Master-Mind Hints (UVA)

题目链接如下:

Online Judge

我的代码如下:

cpp 复制代码
#include <cstdio>
#include <algorithm>
const int maxN = 1000;

int s[maxN], g[maxN], cntS[10], cntG[10];
int N, game, match, tot;

int main(){
    game = 0;
    while(scanf("%d", &N) && N){
        std::fill(cntS, cntS + 10, 0);
        for(int i = 0; i < N; ++i){
            scanf("%d", &s[i]);
            cntS[s[i]]++;
        }
        printf("Game %d:\n", ++game);
        while(1){
            std::fill(cntG, cntG + 10, 0);
            match = 0;
            for(int i = 0; i < N; ++i){
                scanf("%d", &g[i]);
                match += s[i] == g[i] ? 1 : 0;
                cntG[g[i]]++;
            }
            if(!g[0]){
                break;
            }
            tot = 0;
            for(int i = 1; i < 10; ++i){
                tot += std::min(cntS[i], cntG[i]);
            }
            printf("    (%d,%d)\n", match, tot - match);
        }
    }
    return 0;
}
相关推荐
re林檎5 分钟前
算法札记——4.26
算法
tankeven20 分钟前
动态规划专题(10):最优三角剖分问题
c++·算法·动态规划
黑眼圈子24 分钟前
动态规划问题专项练习(未编辑完成...
学习·算法·动态规划
探物 AI26 分钟前
【感知·车道线检测】UFLDv2车道线检测与车道偏离预警(LDWS)实战
人工智能·算法·目标检测·计算机视觉
菜鸟丁小真29 分钟前
LeetCode hot100 -54.螺旋矩阵
算法·leetcode·矩阵·知识点总结
weixin_4684668538 分钟前
排列组合算法之隔板问题与错排公式
c++·算法·数学建模·排列组合·竞赛·错排·隔板
wsoz1 小时前
Leetcode链表-day9
c++·算法·leetcode·链表
Lumos_7771 小时前
Linux -- 系统调用
linux·运维·算法
一个行走的民1 小时前
深度剖析 Ceph PG 分裂机制:原理、底层、实操、影响、线上避坑(最全完整版)
ceph·算法
WolfGang0073211 小时前
代码随想录算法训练营 Day46 | 图论 part04
算法·图论