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)) );
}
}
}

OpenJ_POJ C16B Robot Game 打表找规律的更多相关文章

  1. OpenJ_POJ C16D Extracurricular Sports 打表找规律

    Extracurricular Sports 题目连接: http://acm.hust.edu.cn/vjudge/contest/122701#problem/D Description As w ...

  2. Codeforces Beta Round #24 D. Broken robot (打表找规律)

    题目链接: 点击我打开链接 题目大意: 给你 \(n,j\),再给出 \(m[0]\) 的坐标和\(a[0]-a[n-1]\) 的坐标. 让你输出 \(m[j]\) 的坐标,其中 \(m[i]\) 和 ...

  3. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  4. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  5. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

  6. HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)

    Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  7. 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

  8. HDU 5795 A Simple Nim(SG打表找规律)

    SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...

  9. hdu_5894_hannnnah_j’s Biological Test(打表找规律)

    题目链接:hdu_5894_hannnnah_j’s Biological Test 题意: 有n个不同的位置围成一个圈,现在要安排m个人坐,每个人至少的间隔为k,问有多少种安排 题解: 先打表找规律 ...

随机推荐

  1. Angular 下的 function

    angular.lowercas 将指定的字符串转换为小写的 Usage(使用方法) angular.lowercase(string);   Arguments Param Type Details ...

  2. Spark笔记之数据本地性(data locality)

    一.什么是数据本地性(data locality) 大数据中有一个很有名的概念就是"移动数据不如移动计算",之所以有数据本地性就是因为数据在网络中传输会有不小的I/O消耗,如果能够 ...

  3. 对package.json的理解和学习

    一.初步理解 1. npm安装package.json时  直接转到当前项目目录下用命令npm install 或npm install --save-dev安装即可,自动将package.json中 ...

  4. ZYNQ. Interrupt(2)SPI.AXI TIMER

    Shared Peripheral Interrupts (SPI) SPI 可以接收来自PL的中断,这里使用PL模块 AXI Timer 的中断模式,并连接到CPU. AXI TIMER 定时器,内 ...

  5. 字符串对象的charAt函数存在的意义

    var style = ""; style[0] //undefined var style = ""; style.charAt(0); //"&q ...

  6. LEARN HOW TO HACK

    出处:https://www.hackerone.com/hacker101 什么是HACKER101? https://hacker101.com/Hacker101是一个视频,资源和实践活动的集合 ...

  7. Spring bean 配置

    1.传统的创建对象的方式:JedisMall tardition=new JedisMall(); 这样是在程序运行时创建,表示当前模块已经不知不觉和new出的对象耦合了,而我们通常都是更高层次的抽象 ...

  8. Python多线程-2(线程共享全局变量)

    例子: from threading import Thread,Lock from time import sleep, ctime global_num = [] def func1(): glo ...

  9. metasploit利用漏洞渗透攻击靶机

    1.网络测试环境构建 首先需要先配置好一个渗透测试用的网络环境,包括如图1所示的运行Kali Linux系统的计算机,如图2所示的老师给的Windows Server 2000系统的计算机.这两台计算 ...

  10. 解决连不上dl.google.com和dl-ssl.google.com

    http://ping.chinaz.com/ 开发android遇到的最大问题就是Google被墙了,而我们的sdk又需要通过dl.google.com和dl-ssl.google.com去下载一些 ...