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;
}
相关推荐
Xの哲學1 分钟前
Linux RTC深度剖析:从硬件原理到驱动实践
linux·服务器·算法·架构·边缘计算
狐577 分钟前
2025-12-04-牛客刷题笔记-25_12-4-质数统计
笔记·算法
小O的算法实验室8 分钟前
2024年IEEE IOTJ SCI2区TOP,基于混合算法的水下物联网多AUV未知环境全覆盖搜索方法,深度解析+性能实测
算法·论文复现·智能算法·智能算法改进
洲星河ZXH30 分钟前
Java,比较器
java·开发语言·算法
CoderYanger32 分钟前
递归、搜索与回溯-FloodFill:33.太平洋大西洋水流问题
java·算法·leetcode·1024程序员节
CodeByV40 分钟前
【算法题】双指针(二)
数据结构·算法
点云SLAM1 小时前
Boost库中Math 模块的根搜索 / 根求解和示例
数学·算法·数值优化·根搜索 / 根求解和示例·函数根求解·boost模块
我搞slam2 小时前
EM Planner算法与代码解读
算法
CodeWizard~2 小时前
线性筛法求解欧拉函数以及欧拉反演
算法