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

2017 JUST Programming Contest 3.0 D. Dice Game的更多相关文章

  1. 2017 JUST Programming Contest 2.0 题解

    [题目链接] A - On The Way to Lucky Plaza 首先,$n>m$或$k>m$或$k>n$就无解. 设$p = \frac{A}{B}$,$ans = C_{ ...

  2. gym101532 2017 JUST Programming Contest 4.0

    台州学院ICPC赛前训练5 人生第一次ak,而且ak得还蛮快的,感谢队友带我飞 A 直接用claris的模板啊,他模板确实比较强大,其实就是因为更新的很快 #include<bits/stdc+ ...

  3. 2017 JUST Programming Contest 3.0 B. Linear Algebra Test

    B. Linear Algebra Test time limit per test 3.0 s memory limit per test 256 MB input standard input o ...

  4. 2017 JUST Programming Contest 3.0 I. Move Between Numbers

    I. Move Between Numbers time limit per test 2.0 s memory limit per test 256 MB input standard input ...

  5. 2017 JUST Programming Contest 3.0 H. Eyad and Math

    H. Eyad and Math time limit per test 2.0 s memory limit per test 256 MB input standard input output ...

  6. 2017 JUST Programming Contest 3.0 K. Malek and Summer Semester

    K. Malek and Summer Semester time limit per test 1.0 s memory limit per test 256 MB input standard i ...

  7. 2017 JUST Programming Contest 3.0 E. The Architect Omar

    E. The Architect Omar time limit per test 1.0 s memory limit per test 256 MB input standard input ou ...

  8. gym101343 2017 JUST Programming Contest 2.0

    A.On The Way to Lucky Plaza  (数论)题意:m个店 每个店可以买一个小球的概率为p       求恰好在第m个店买到k个小球的概率 题解:求在前m-1个店买k-1个球再*p ...

  9. 2017 JUST Programming Contest 2.0

    B. So You Think You Can Count? 设dp[i]表示以i为结尾的方案数,每个位置最多往前扫10位 #include<bits/stdc++.h> using na ...

随机推荐

  1. Android实战简易教程-第三十九枪(第三方短信验证平台Mob和验证码自己主动填入功能结合实例)

    用户注冊或者找回password时通常会用到短信验证功能.这里我们使用第三方的短信平台进行验证实例. 我们用到第三方短信验证平台是Mob,地址为:http://mob.com/ 一.注冊用户.获取SD ...

  2. sendEmail实现邮件报警发送

    安装wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz tar -xf sendEmail-v ...

  3. dnsmasq possible DNS-rebind attack detected错误

    最近在做openwrt的平台,dns使用的是dnsmasq,但是通过板子上网,将PC的dns设置成板子的时候,发现百度等都可以,但是公司邮箱打不开.公司邮箱的域名 xx-xx-notes.xxx.co ...

  4. 【APUE】文件I/O

    Linux的内核将所有外部设备都可以看做一个文件来操作.那么我们对与外部设备的操作都可以看做对文件进行操作.我们对一个文件的读写,都通过调用内核提供的系统调用:内核给我们返回一个file descri ...

  5. 【转】Linux下添加新硬盘,分区及挂载

    原文:http://blog.chinaunix.net/uid-25829053-id-3067619.html ------------------------------------------ ...

  6. Java编程50题

    [程序1]    题目:古典问题:有一对兔子.从出生后第3个月起每一个月都生一对兔子,小兔子长到第三个月后每一个月又生一对兔子,假如兔子都不死.问每一个月的兔子总数为多少?    //这是一个菲波拉契 ...

  7. #define中的#和##作用

    #define语句中的#是把参数字符串化,##是连接两个参数成为一个整体. #define FACTORY_REF(name) { #name, Make##name } 中#name就是将传入的na ...

  8. ganglia监控自己定义metric实践

    Ganglia监控系统是UC Berkeley开源的一个项目,设计初衷就是要做好分布式集群的监控.监控层面包含资源层面和业务层面,资源层面包含cpu.memory.disk.IO.网络负载等,至于业务 ...

  9. java集群优化——多线程下的单例模式

    在最初学习设计模式时,我为绝佳的设计思想激动不已,在以后的project中.多次融合设计模式,而在当下的设计中.我们已经觉察出了当初设计模式的高瞻远瞩.可是也有一些不足,须要我们去改进.有人说过.世界 ...

  10. 记一次UICollectionView中visibleCells的坑

    记一次UICollectionView中visibleCells的坑 项目的要求是这样的 其实也是一个轮播图,而已,所以依照轮播图的实现原理,这里觉得也很简单,还是利用UICollectionView ...