OpenJ_POJ C16B Robot Game 打表找规律

Robot Game

题目连接:

http://acm.hust.edu.cn/vjudge/contest/122701#problem/B

Description

Sgeoghy has addicted herself to an interesting computer game! In this game, she needs to control a robot to pick up a required number of components. There are a lot of components lying in a line with arbitrary intervals, indexed from left to right, starting with 1. No two or more components share the same position. In the beginning, the robot starts at a random position where a component lies, and the robot should pick it up. Then on each step, the player can program the robot, by controlling its moving direction (left or right) as well as moving distance. After each step of moving, if there is a component at the destination, the robot will pick it up; But if not, the robot will die and the game will be over.

Unfortunately, Sgeoghy is poor at programming. She can only make the robot move a fixed distance towards a fixed direction (left or right) every single step. For example, the positions of the components are:

and the robot starts at the position of 5-th component. If Sgeoghy controls the robot to move a fixed distance 2 and a fixed direction right on each step, the robot can pick up 3 components indexed as 5, 6, 8, and dies at Position 15.

At first, Sgeoghy can barely complete the missions. However, since the mission is getting harder and harder, she is getting stuck. Now she is facing a mission that the positions of the components are:

and the robot starts at the position of y-th component. The robot is required to pick up 100 components to complete this mission. Can you help her? Since she can only program the robot to move a fixed distance towards a fixed direction, it may be impossible for her to complete this mission. However, you should still tell her the most components she can get.

Input

The first line contains an integer T (1 ≤ T ≤ 30), indicating the number of test cases.

For each test case:

A line contains an integer y (1 ≤ y ≤ 10^100), indicating that the robot starts at the position of y-th component.

Output

For each test case:

The first line contains an integer n, indicating either the maximum possible number of components (1 ≤ n < 100) that the robot can pick up in this mission, or n=100 if Sgeoghy is able to complete this mission.

Then follows n lines, the i-th line contains an integer xi, indicating the index of the i-th component picked up by the robot. Obviously, x1=y and x1,x2,...,xn are sequenced in strictly monotonic order. If there are several solutions, output any one.

Sample Input

1
7661

Sample Output

3
7661
5417
5

Hint

题意

第i个零件的位置是i(i+1)

有个机器人,一开始站在第y个零件的位置,这个机器人只能往前一直走,或者一直往下走,然后每一步的距离也必须相同,且每一步都必须踩到零件上面。

问你这个机器人最多走多少步,且把每一步的零件坐标输出。

题解:

看了下样例,感觉最多走三步。

打表找规律,发现输入x,输出5x+2,和7x+3就好了

猜到结论之后,证明就很简单了,这儿省略。

代码

import java.io.*;
import java.math.*;
import java.util.*;


public class Main
{
    public static void main(String argv[]) throws Exception
    {
        Scanner cin = new Scanner(System.in);
        int T = cin.nextInt();
        for( int cas = 1 ; cas <= T ; ++ cas ){
            BigInteger index = cin.nextBigInteger();
            System.out.println("3");
            System.out.println( index );
            System.out.println( index.multiply(BigInteger.valueOf(5)).add(BigInteger.valueOf(2)) );
            System.out.println( index.multiply(BigInteger.valueOf(7)).add(BigInteger.valueOf(3)) );
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值