ZOJ One Person Game

目录

1.题目

2.中文翻译

3.思路解析:

4.代码实现:


1.题目

One Person Game

Description 

        There is an interesting and simple one person game. Suppose there is a number axis under your feet. You are at point  A  at first and your aim is point  B . There are 6 kinds of operations you can perform in one step. That is to go left or right by  a,b  and  c , here  c  always equals to  a+b .

        You must arrive B as soon as possible. Please calculate the minimum number of steps.

Input
        There are multiple test cases. The first line of input is an integer $T(0 < T ≤ 1000) $indicates the number of test cases. Then T test cases follow. Each test case is represented by a line containing four integers 4 integers A, B, a and b, separated by spaces. ($-2^{31} ≤ A, B < 2^{31}, 0 < a, b < 2^{31}$)

Output
 For each test case, output the minimum number of steps. If it’s impossible to reach point B, output “-1” instead.

Examples
intput

2
0 1 1 2
0 1 2 4

output

1
-1

2.中文翻译

题目描述

        有一个有趣而简单的单人游戏。假设你脚下有一个数字轴。你一开始是在点 A ,你的目标是点  B  。一步可以执行6种操作。也就是向左或向右移动 a、b 和 c ,这里 c 总是等于 a+b 。

        你必须尽快到达B。请计算最小步数。

输入

        有多个测试用例。输入的第一行是一个整数 T(0<T≤1000) 表示测试用例的数量。然后是T行测试案例。每个测试用例由一行表示,该行包含四个整数4个整数 A、B、a 和 b,用空格分隔。(-2^{31}≤A,B<2^{31},0<A,B<2^{3})

输出

        对于每个测试用例,输出最小步骤数。如果无法到达B点,则输出“-1”。

样例输入

样例输出

3.思路解析:

        1.题目其实就是求 C1*a + C2*b + C3*c + C4*(-a)+C5*(-b)+C6*(-c)| = |A-B|,根据题意化简之后就变成了 |C1a+C_2b| = |A-B| ,目的就是判断左边这个方程是否有解.

        2.欧几里得扩展算法:我的算法专栏里面有讲解。

4.代码实现:

#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int N = 1e5+10;
 
LL exgcd(LL a,LL b,LL &x,LL &y)
{
    if(b==0)
    {
        x=1, y=0;
        return a;
    }
    LL ans=exgcd(b,a%b,x,y);
    LL tmp=x;
    x=y;
    y=tmp-a/b*y;
    return ans;
}
 
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        LL A, B, a, b, c, x, y;
        scanf("%lld %lld %lld %lld",&A, &B, &a, &b);
        if(A>B) swap(A,B);
        c=(B-A);
        LL g=exgcd(a,b, x, y);
        if(c%g!=0) puts("-1");
        else
        {
            a/=g, b/=g;
            x*=(c/g), y*=(c/g);
            LL k=(y-x)/(a+b);
            LL ans=10000000000ll;
            for(LL i=k-1;i<=k+1;i++)
            {
                if(abs(x+i*b)+abs(y-i*a)==abs(x+i*b+y-i*a)) ans=min(ans,max(abs(x+i*b),abs(y-i*a)));
                else   ans=min(ans,abs(x+i*b)+abs(y-i*a));
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}

     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Introduction ..................................... xviii Chapter 1 What Players Want ....................1 Why Do Players Play?..................................2 Players Want a Challenge ..............................2 Players Want to Socialize ..............................3 Players Want a Dynamic Solitaire Experience....................5 Players Want Bragging Rights ............................5 Players Want an Emotional Experience .......................6 Players Want to Fantasize ..............................7 What Do Players Expect? ................................8 Players Expect a Consistent World..........................8 Players Expect to Understand the Game-World’s Bounds .............9 Players Expect Reasonable Solutions to Work...................10 Players Expect Direction ..............................10 Players Expect to Accomplish a Task Incrementally................12 Players Expect to Be Immersed...........................12 Players Expect to Fail................................14 Players Expect a Fair Chance............................14 Players Expect to Not Need to Repeat Themselves ................15 Players Expect to Not Get Hopelessly Stuck....................16 Players Expect to Do, Not to Watch ........................17 Players Do Not Know What They Want, But They Know It When They See It . 18 A Never-Ending List..................................19 Chapter 2 Interview: Sid Meier ..................20 Chapter 3 Brainstorming a Game Idea: Gameplay, Technology, and Story ......................42 Starting Points .....................................43 Starting with Gameplay...............................44 Starting with Technology ..............................45 Starting with Story .................................47 Working with Limitations ...............................50 Odyssey: The Legend of Nemesis..........................50 ix Contents Damage Incorporated................................51 Centipede 3D ..............................
Beginning 3D Game Development with Unity 992 pages Publisher: Apress; 1 edition (May 25, 2011) Language: English ISBN-10: 1430234229 ISBN-13: 978-1430234227 What you’ll learn How to build interactive games that work on a variety of platforms Take the tour around Unity user interface fundamentals, scripting and more Create a test environment and gain control over functionality, cursor control, action objects, state management, object metadata, message text and more What is inventory logic and how to manage it How to handle 3D object visibility, effects and other special cases How to handle variety of menus and levels in your games development How to handle characters, scrollers, and more How to create or integrate a story/walkthrough Real time 3D games have been around for well over ten years now. We’ve played them, created assets in the style of our favorites, and maybe even “mod”ed a few of them. But until recently, the cost of licensing one of the premier game engines has ranged from several hundred thousand to several million dollars per title (!), relegating the dream of creating your own 3D game to an unattainable fantasy. Times have changed. 3D has become affordable not only in the movie industry, as seen by the number of titles featuring CG (computer graphics), but also in the game industry where we’ve seen a shift in casual games from 2D to a 3D format. With Unity’s bold move to offer a robustly featured free version of their engine, a radical change in the pricing models of the high-end engines has rocked the industry. The cost of the engine is no longer a barrier to taking your game from a nebulous idea to a working prototype and even on to a marketable product. Whether your interest is in casual games or you have more ambitious aims, if you have no previous scripting experience but are eager to bring your art assets and story to life, this may be just the book to get you underway. In today’s modern game engines, the heavy programming is handled by the engine itself, so the logic and game play can be scripted by those with more creativity than traditional programming knowledge. In this book, I will approach game creation and design decisions from a 3D artist’s view, taking the logic and scripting in small pieces, while introducing artists, budding game designers, and novice programmers to real-time game engine concepts at the same time. This book is written in a project-based format so you will not only end up with a playable game and scripting resources you can reuse for other games, but you will experience typical design decisions that need to be addressed throughout the process. You will create your game by starting with the basics and refining it as you add functionality; I will explain the logic behind certain choices and real-time game concepts as you go along. The project for this book is based on a first person point and click adventure game, complete with inventory, state management, load/save functionality, and a strong emphasis on the visual aspects of game creation. Even if you are more of a first person shooter-type game enthusiast, you will be able to see how including entertaining or interesting tasks and features can enhance your favorite genre. The aim of this project is to introduce you to a logical progression of design decisions and problem solving that will be of value well beyond the scope of the adventure game genre. It provides a framework and a methodology for creating and, more importantly, finishing your own game. You will be going beyond the basic Unity functionality and use of standard assets to investigate topics rarely covered in online tutorials or books. All of the necessary art assets to complete the project are provided.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值