HDOJ(HDU) 1562 Guess the number(水题,枚举就行)

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

枚举就可以了。。

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            boolean is = true;
            int tm=a;
            while(a<1000){
                a=a+tm;
            }

            //注意!答案的范围是[1000,9999]
            for (int i = a; i < 10000; i = i + tm) {
                //此处注意i是加tm,而不是再加a了,因为a可能变了。
                if ((i+1)%b==0&&(i+2)%c==0) {
                    System.out.println(i);
                    is = false;
                    break;
                }
            }

            if (is) {
                System.out.println("Impossible");
            }

        }
    }

}
时间: 2024-08-24 07:23:22

HDOJ(HDU) 1562 Guess the number(水题,枚举就行)的相关文章

HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)

Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or the film of the same name by Stanley Kubrick. In it a spaceship is sent from Earth to Saturn. The crew is put into stasis for the long flight, only tw

HDOJ(HDU) 1555 How many days?(水题)

Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, k,(2 <= k <= M <= 1000).M = 0, k = 0代表输入结束. Output 对于每个测试实例输出一个整数,表示M元可以用的天数. Sample Input 2 2 4 3 0 0 Sample Output 3 5 水题.... import java.util.

HDOJ/HDU 2537 8球胜负(水题.简单的判断)

Problem Description 8球是一种台球竞赛的规则.台面上有7个红球.7个黄球以及一个黑球,当然还有一个白球.对于本题,我们使用如下的简化规则:红.黄两名选手轮流用白球击打各自颜色的球,如果将该颜色的7个球全部打进,则这名选手可以打黑球,如果打进则算他胜.如果在打进自己颜色的所有球之前就把黑球打进,则算输.如果选手不慎打进了对手的球,入球依然有效. 现在给出打进的球(白球除外)的顺序,以及黑球由哪方打进,你的任务是判定哪方是胜者. 假设不会有一杆同时打进一颗黑球和其他彩球. Inp

HDOJ(HDU) 2137 circumgyrate the string(此题用Java-AC不过!坑)

此题如果有用JavaACDSee,请评论,谢谢了. Problem Description Give you a string, just circumgyrate. The number N means you just circumgyrate the string N times, and each time you circumgyrate the string for 45 degree anticlockwise. Input In each case there is string

HDOJ(HDU) 2123 An easy problem(简单题...)

Problem Description In this problem you need to make a multiply table of N * N ,just like the sample out. The element in the ith row and jth column should be the product(乘积) of i and j. Input The first line of input is an integer C which indicate the

HDOJ/HDU 2560 Buildings(嗯~水题)

Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, the green grids represent the buidings. Given the size of the HZNU Campus, and the color of each grid, you should count how many green grids in the N

HDOJ/HDU 1256 画8(绞下思维~水题)

Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一个整数,字符表示画笔,整数(>=5)表示高度. Output 画横线总是一个字符粗,竖线随着总高度每增长6而增加1个字符宽.当总高度从5增加到6时,其竖线宽度从1增长到2.下圈高度不小于上圈高度,但应尽量接近上圈高度,且下圈的内径呈正方形. 每画一个"8"应空一行,但最前和最后都无空

HDOJ(HDU) 1859 最小长方形(水题、、)

Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内. Input 测试输入包含若干测试用例,每个测试用例由一系列坐标组成,每对坐标占一行,其中|x|和|y|小于 231:一对0 坐标标志着一个测试用例的结束.注意(0, 0)不作为任何一个测试用例里面的点.一个没有点的测试用例标志着整个输入的结束. Output 对每个测试用例,在1行内输出2对整数

HDOJ(HDU) 2500 做一个正气的杭电人(水~)

Problem Description 做人要有一身正气,杭电学子都应该如此.比如我们今天的考试就应该做到"诚信"为上. 每次考试的第一个题目总是很简单,今天也不例外,本题是要求输出指定大小的"HDU"字符串,特别地,为了体现"正气"二字,我们要求输出的字符串也是正方形的(行数和列数相等). Input 输入的第一行包含一个正整数N(N<=20),表示一共有N组数据,接着是N行数据,每行包含一个正整数M(M<=50),表示一行内有M个