zoukankan      html  css  js  c++  java
  • HDU 1562 Guess the number

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1562

    Problem Description
    Happy new year to everybody!
    Now, I want you to guess a minimum number x betwwn 1000 and 9999 to let 
    (1) x % a = 0;
    (2) (x+1) % b = 0;
    (3) (x+2) % c = 0;
    and a, b, c are integers between 1 and 100.
    Given a,b,c, tell me what is the number of x ?
     

    Input
    The number of test cases c is in the first line of input, then c test cases followed.every test contains three integers a, b, c.
     

    Output
    For each test case your program should output one line with the minimal number x, you should remember that x is between 1000 and 9999. If there is no answer for x, output "Impossible".
     

    Sample Input
    2
    44 38 49
    25 56 3
     

    Sample Output
    Impossible
    2575
     

    Author
    8600
     1 #include<stdio.h>
     2 #include<iostream>
     3 using namespace std;
     4 int main()
     5 {
     6     int T;
     7     int a,b,c,x;
     8     bool flag1,flag2,flag3;
     9     cin>>T;
    10     while(T--)
    11     {
    12         cin>>a>>b>>c;
    13         flag1=false;flag2=false;flag3=false;
    14         for(x=1000;x<=9999;x++)//预处理防止超时 
    15         {
    16             if(x%a==0)
    17             {
    18                 flag1=true;
    19                 break;
    20             }
    21         }
    22         if(flag1)
    23         {
    24             for(;x<=9999;x+=a)
    25             {
    26                 if((x+1)%b==0&&(x+2)%c==0)
    27                 {
    28                     flag2=true;
    29                     cout<<x<<endl;
    30                     break;
    31                 }
    32             }
    33         }
    34         if(!flag2)
    35         cout<<"Impossible"<<endl;
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    timeout in asp.net
    ASP.NET_SessionId vs .ASPXAUTH why do we need both of them?
    Visual paradigm软件介绍
    OJ网站程序员必备
    c++异常详解
    C++STL之双端队列容器
    GPU的线程模型和内存模型
    C++ 中memset 勿要对类使用
    trait与policy模板技术
    C++标准库
  • 原文地址:https://www.cnblogs.com/Annetree/p/5735258.html
Copyright © 2011-2022 走看看