zoukankan      html  css  js  c++  java
  • 2017 JUST Programming Contest 3.0 D. Dice Game



    D. Dice Game
    time limit per test
    1.0 s
    memory limit per test
    256 MB
    input
    standard input
    output
    standard output

    A dice is a small cube, with each side having a different number of spots on it, ranging from 1 to 6.

    Each side in the dice has 4 adjacent sides that can be reached by rotating the dice (i.e. the current side) 90 degrees. The following picture can help you to conclude the adjacent sides for each side in the dice.

    In this problem, you are given a dice with the side containing 1 spot facing upwards, and a sum n, your task is to find the minimum number of required moves to reach the given sum.

    On each move, you can rotate the dice 90 degrees to get one of the adjacent sides to the side that currently facing upwards, and add the value of the new side to your current sum. According to the previous picture, if the side that currently facing upwards contains 1 spot, then in one move you can move to one of sides that contain 2, 3, 4, or 5 spots.

    Initially, your current sum is 0. Even though at the beginning the side that containing 1 spot is facing upwards, but its value will not be added to your sum from the beginning, which means that you must make at least one move to start adding values to your current sum.

    Input

    The first line contains an integer T (1 ≤ T ≤ 200), where T is the number of test cases.

    Then T lines follow, each line contains an integer n (1 ≤ n ≤ 104), where n is the required sum you need to reach.

    Output

    For each test case, print a single line containing the minimum number of required moves to reach the given sum. If there is no answer, print -1.

    Example
    input
    2
    5
    10
    
    output
    1
    2
    
    Note

    In the first test case, you can rotate the dice 90 degrees one time, and make the side that contains 5 spots facing upwards, which make the current sum equal to 5. So, you need one move to reach sum equal to 5.

    In the second test case, you can rotate the dice 90 degrees one time, and make the side that contains 4 spots facing upwards, which make the current sum equal to 4. Then rotate the dice another 90 degrees, and make the side that contains 6 spots facing upwards, which make the current sum equal to 10. So, you need two moves to reach sum equal to 10.



    #include<iostream>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    #define ll long long
    const int maxn=100005;
    
    int a[25]={0,1,1,1,1,1,
                2,3,2,2,2,
                2,3,3,3,3,
                3,4,4,4,4,4,4
                };
    
    int main()
    {
    //    freopen("in.txt","r",stdin);
        int T,n;
        scanf("%d",&T);
        int yu,bei;
        while(T--)
        {
            int ans=0;
            scanf("%d",&n);
            if(n==1)
                cout<<-1<<endl;
            else if(n<=11)
                cout<<a[n]<<endl;
            else if(n>11)
            {
                while(n>11){
                    n-=11;
                    ans+=2;
                }
                if(n==7)
                    ans-=1;
                ans+=a[n];
                cout<<ans<<endl;
            }
        }
    }


  • 相关阅读:
    基于struts2和hibernate的登录和注册功能——完整实例
    (转载)Hibernate的事务管理
    (转载)hibernate缓存
    Hibernate映射解析——七种映射关系
    Hibernate核心组件详解
    Struts2国际化——完整实例代码
    Struts2的手工自定义验证--完整实例代码
    Struts2内置校验器——完整实例代码
    Struts2自定义拦截器——完整实例代码
    Struts2工作原理及流程
  • 原文地址:https://www.cnblogs.com/bryce1010/p/9387152.html
Copyright © 2011-2022 走看看