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)) );
}
}
}
OpenJ_POJ C16B Robot Game 打表找规律的更多相关文章
- OpenJ_POJ C16D Extracurricular Sports 打表找规律
Extracurricular Sports 题目连接: http://acm.hust.edu.cn/vjudge/contest/122701#problem/D Description As w ...
- Codeforces Beta Round #24 D. Broken robot (打表找规律)
题目链接: 点击我打开链接 题目大意: 给你 \(n,j\),再给出 \(m[0]\) 的坐标和\(a[0]-a[n-1]\) 的坐标. 让你输出 \(m[j]\) 的坐标,其中 \(m[i]\) 和 ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
- 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 ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- hdu_5894_hannnnah_j’s Biological Test(打表找规律)
题目链接:hdu_5894_hannnnah_j’s Biological Test 题意: 有n个不同的位置围成一个圈,现在要安排m个人坐,每个人至少的间隔为k,问有多少种安排 题解: 先打表找规律 ...
随机推荐
- Linux命令(四)文件传输
1. 将当前目录下的test1.txt文件,复制到 /tmp/Douzi目录下,命名为test1.py 2. 将服务器/tmp/Douzi/hello.py复制到本地上,重命名为 hello_Do ...
- Eclipse的个性化设置
Eclipse的个性化设置 1. 在Eclipse中查看JDK源码的配置 a. 点 “window”-> "Preferences" -> "Java&quo ...
- eclipse中可以导入其它工具编写的RobotFramework脚本吗?
在Robotframework的官方网站中,提供了非常多的编辑RF的工具.比如Ride,eclipse,sublime,notepad++等. 网上查到的资料,大部分都是Ride这个编辑工具的使用.在 ...
- 【CTF WEB】XSS-https://alf.nu/alert1
XSS练习平台 https://alf.nu/alert1 Warmup 1");alert(1)// Adobe 1");alert(1)// JSON </script& ...
- python3之模块urllib
urllib是python内置的HTTP请求库,无需安装即可使用,它包含了4个模块: request:它是最基本的http请求模块,用来模拟发送请求 error:异常处理模块,如果出现错误可以捕获这些 ...
- Linux Power Managment详解 【转】
转自:http://blog.chinaunix.net/uid-24517893-id-254740.html Linux Power Managment 谨以此文纪念过往的岁月 一.前言 在这个对 ...
- Python3安装配置【转】
不建议卸载python2 可能会导致系统内其他软件无法使用,如果使用最新的Python3那么我们知道编译安装源码包和系统默认包之间是没有任何影响的,所以可以安装python3和python2共存 (前 ...
- Docker手动搭建sentry错误日志系统
Sentry介绍 在开发过程中,我们通过debug来排查bug,并且使用logging来记录系统的错误.但是logging有很多不足: 必须登陆到服务器查看日志文件 需要主动去查询 输出日志方式无法把 ...
- centos6.5环境Redis下载及编译安装
centos6.5环境Redis下载及编译安装 1:官方站点: http://redis.io/download 下载最新版或者最新stable版 2:解压源码并进入目录 tar -zxvf redi ...
- idea如何编译maven项目
这里我们介绍两种方式,如何调试出窗口 点击菜单栏View->Tool Windows->Maven projects 点击菜单栏Help->Find Action(Ctrl+Shi ...