2017 JUST Programming Contest 3.0 D. Dice Game
1.0 s
256 MB
standard input
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.
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.
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.
2
5
10
1
2
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的更多相关文章
- 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_{ ...
- gym101532 2017 JUST Programming Contest 4.0
台州学院ICPC赛前训练5 人生第一次ak,而且ak得还蛮快的,感谢队友带我飞 A 直接用claris的模板啊,他模板确实比较强大,其实就是因为更新的很快 #include<bits/stdc+ ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- gym101343 2017 JUST Programming Contest 2.0
A.On The Way to Lucky Plaza (数论)题意:m个店 每个店可以买一个小球的概率为p 求恰好在第m个店买到k个小球的概率 题解:求在前m-1个店买k-1个球再*p ...
- 2017 JUST Programming Contest 2.0
B. So You Think You Can Count? 设dp[i]表示以i为结尾的方案数,每个位置最多往前扫10位 #include<bits/stdc++.h> using na ...
随机推荐
- lemon oa前端页面——由user-base-list谈项目组织
content user-base-list.jsp中指定<%pageContext.setAttribute("currentHeader", "user&quo ...
- Ubuntu系统U盘安装以及降内核
由于项目需要,要用U盘制作一个Linux系统,支持EFI启动,并且内核版本要求是2.6.35.6.所以在选系统的时候,就必须要选安装文件里面带有EF I目录,并且该目录下面有BOOTx64.EFI和g ...
- php monolog 的写日志到unix domain socket 测试终于成功
在另外一个客户端执行 php s.php后, 通过nc -lU /tmp/tg.sck 建立的unix domain socket 有接收到消息. <?php require 'vendor/a ...
- javascript闭包诡异的问题
var funcs = []; for (var i = 0; i < 3; i++) { // let's create 3 functions funcs[i] = function() { ...
- webpack-Manifest
Manifest 在使用 webpack 构建的典型应用程序或站点中,有三种主要的代码类型: 你或你的团队编写的源码. 你的源码会依赖的任何第三方的 library 或 "vendor&qu ...
- Guice 学习(八)AOP (面向切面的编程)
Guice的AOP还是非常弱的.眼下只支持方法级别上的,另外灵活性也不是非常高. 看例如以下演示样例: Guice支持AOP的条件是: 类必须是public或者package (default) 类不 ...
- Linux Chromium安装Adobe Flash Player
首先,下载: install_flash_player_11_linux.i386.tar.gz 解压文件: tar -xvf install_flash_player_11_linux.i386.t ...
- 对于api安全性的思考
目前的情况下api被很多地方应用,随之而来的是api的安全性问题. 我所认识到的安全性问题有以下几个方面: 1.DDoS(拒绝服务攻击),接口被恶意调用,使真实的用户无法享受到正常畅通的服务. ...
- 2016/05/25 empty() 与 isset()的区别
对于初学php的人来说,empty()和和isset()用法的区别是很难搞清楚的,他们的用法的差别不仔细去琢磨的话确实很难弄清楚. 先说一下他们的共同点: 都可以判定一个变量是否为空: 都返回bool ...
- BLE广播数据的抓包解析
前言: 报文由数据字节组成同时是按比特传输的,这就免不了牵涉到字节序的问题. 对于各个字节的传输,总是从最低位开始传输.如0x80是按00000001发送的,0x01是按10000000发送的. 同时 ...