nyoj 34-韩信点兵(暴力)

34-韩信点兵


内存限制:64MB 时间限制:3000ms Special Judge: No
accepted:34 submit:41

题目描述:

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

输入描述:

输入3个非负整数a,b,c ,表示每种队形排尾的人数(a<3,b<5,c<7)。例如,输入:2 4 5

输出描述:

输出总人数的最小值(或报告无解,即输出No answer)。实例,输出:89

样例输入:

2 1 6

样例输出:

41

分析:
  直接暴力10~100以内的数,判断是否满足题目所给的整除条件

C/C++代码实现(AC):
  
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <cmath>
 6 #include <stack>
 7 #include <map>
 8 #include <queue>
 9 #include <set>
10 
11 using namespace std;
12 
13 bool judge(int n, int a, int b, int c)
14 {
15     if((n-a)%3 == 0 && (n-b)%5 == 0 && (n-c)%7 == 0) return true;
16     return false;
17 }
18 
19 int main()
20 {
21 
22     int a, b, c;
23     scanf("%d%d%d", &a, &b, &c);
24     for(int i = 10; i <= 100; ++ i)
25     {
26         if(judge(i, a, b, c))
27         {
28             printf("%d
", i);
29             return 0;
30         }
31     }
32     printf("No answer
");
33 
34     return 0;
35 }

原文地址:https://www.cnblogs.com/GetcharZp/p/9069821.html