zoukankan      html  css  js  c++  java
  • 日常-acm-韩信点兵

       相传韩信才智过人,从不直接清点自己军队的人数,只要让士兵先后以三人一排,五人一排,七人一排地变换队形,而他每次只看一眼队伍的排尾就知道人数了。输入包含多组数据,每组数据包含三个非负整数a,b,c,表示每种队形排尾的人数(a<3,b<5,c<7),输出总人数的最小值(或者报告无解)。已知总人数不小于10,不超过100。

      样例输入:

      2 1 6

      2 1 3

      样例输出:

      Case 1:41

      Case 2:No answer

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<windows.h>
     4 
     5 using namespace std;
     6 //以上文件部分相当于#include<stdio.h>
     7 
     8 int main()
     9 {
    10     int a,b,c;                          //定义数据
    11     int cishu=0;                        //第几次输入
    12     while(cin>>a>>b>>c)
    13     {
    14         cishu++;                        //进来就是要输出
    15         int flag=0;                     //flag为0就是No answer
    16         for(int i=10; i<=100; i++)      //人数范围是10-100
    17         {
    18             //3,5,7三次走法,排尾人数就是整除3,5,7以后的余数
    19             //案例不多所以直接暴力破解就好
    20             //所有可能取值全部拿出来尝试
    21             //人数减差值就是一个可以刚好可以整除的数
    22             if((i-a)%3==0&&(i-b)%5==0&&(i-c)%7==0){
    23                 cout<<"Case "<<cishu<<":"<<i<<endl;
    24                 flag=1;                 //输出以后更改flag
    25                 break;
    26             }
    27         }
    28         if(flag==0)                     //输出不存在的情况
    29             cout<<"Case "<<cishu<<":No answer"<<endl;
    30     }
    31     system("pause");
    32     return 0;
    33 }
  • 相关阅读:
    CNN comprehension
    Gradient Descent
    Various Optimization Algorithms For Training Neural Network
    gerrit workflow
    jenkins job配置脚本化
    Jenkins pipeline jobs隐式传参
    make words counter for image with the help of paddlehub model
    make words counter for image with the help of paddlehub model
    git push and gerrit code review
    image similarity
  • 原文地址:https://www.cnblogs.com/qq1353842241/p/7956532.html
Copyright © 2011-2022 走看看