• [C++]2-2 韩信点兵


    /*
        韩信点兵
        相传韩信才智过人,从不直接清点自己军队的人数,只要让士兵先后以三人一排、五人一排、七人一排地变换队
        形,而他每次只掠一眼队伍的排尾就知道总人数了。输入多组数据,每组数据包含3个非负整数a,b,c,表示每种
        队形排尾的人数(a<3,b<5,c<7),输出总人数的最小值(或报告无解)。已知总人数不小于10,不超过100.输入
        到文件结束为止。
    */
    # define LOCAL
    #include<stdio.h>
    #include<time.h>
    
    int main(){
    #ifdef LOCAL
        freopen("data.in","r", stdin);
        freopen("data.out","w", stdout);
    #endif // LOCAL
    
        int a, b, c;
        int peoples, cases=0;
        while(scanf("%d %d %d", &a, &b, &c) == 3){
            cases++;
    
            peoples = -1;
            for(int i = 10; i < 100; i++){
                if((i % 3 == a) && (i % 5 == b) && (i % 7 == c)){
                    peoples = i;
                }
            }
            if(peoples > 0){
                 printf("Case %d: %d
    ", cases, peoples);
            } else {
                printf("Case %d: No Answer
    ", cases);
            }
        }
    
        return 0;
    }
    /*
    [input]
    2 1 6
    2 1 3
    
    [output]
    Case 1: 41
    Case 2: No Answer
    */
    

    【参考文献】

      刘汝佳.《算法竞赛入门经典》

     

  • 相关阅读:
    linux性能查看调优
    免密登录
    nginx配置
    Samba
    硬RAID与软RAID的区别
    LVM-扩容目录
    解决表面磁盘满,而实际没有大文件的问题
    LINUX下的JENKINS+TOMCAT+MAVEN+GIT+SHELL环境的搭建使用(JENKINS自动化部署)
    Docker 容器使用
    docker基础
  • 原文地址:https://www.cnblogs.com/johnnyzen/p/9067146.html
Copyright © 2020-2023  润新知