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. html5 canvas 多个填充渐变形状

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. MFS - MooseFS 文件系统

    MFSMooseFS 文件系统 可以实现RAID 功能:节约成本 实现在线扩展:是一种半分布式文件系统. 一.MFS文件系统的组成 1.mfsmaster 元数据服务器. 在整个体系中负责管理管理文件 ...

  3. 第11月第3天 直播 rtmp yuv

    1. LiveVideoCoreSDK AudioUnitRender ==> MicSource::inputCallback ==> GenericAudioMixer::pushBu ...

  4. 第10月第20天 afnetwork like MKNetworkEngine http post

    1. + (AFHTTPRequestOperation *)requestSellerWithCompletion:(requestFinishedCompletionBlock)successBl ...

  5. 第7月第12天 opengles background

    1. After your app exits its applicationDidEnterBackground: method, it must not make any new OpenGL E ...

  6. py-faster-rcnn代码阅读2-config.py

    简介  该文件指定了用于fast rcnn训练的默认config选项,不能随意更改,如需更改,应当用yaml再写一个config_file,然后使用cfg_from_file(filename)导入以 ...

  7. mybatis开发dao的方法——(三)

    ------------------------1.    SqlSession使用范围------------------- 1.1     SqlSessionFactoryBuilder 通过S ...

  8. xtrabackup 恢复单个表【转】

    一.安装与备份 1. 下载安装XtraBackup$wget http://www.percona.com/redir/downloads/XtraBackup/LATEST/binary/tarba ...

  9. nginx tomcat 自动部署python脚本【转】

    #!/usr/bin/env python #--coding:utf8-- import sys,subprocess,os,datetime,paramiko,re local_path='/ho ...

  10. centos7.2环境yum方式快速搭建lnmp环境nginx+mariadb+php-fpm

    centos7.2环境yum方式安装nginx+mariadb+php-fpm 1.安装lnmp环境 安装epel源 yum install -y epel-release 安装 MySQL + PH ...