X: Yet Another Die Game(AtCoder-2298)

Problem Description

Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7.

Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:

Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward.
For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back.

Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.

Constraints

  • 1≦x≦1015
  • x is an integer.

Input

The input is given from Standard Input in the following format:

x

Output

Print the answer.

Example

Sample Input 1

7

Sample Output 1

2

Sample Input 2

149696127901

Sample Output 2

27217477801

题意:给出一个骰子,骰子对立两面的和为 7,现在每次可以将骰子向相邻的方向翻转一次,翻转后朝上的一面为得分,问翻转多少次后,得分至少为 x

思路:

由于初始时骰子朝上的点数没有要求,因此当 x 小于等于 6 时,让点数为 x 的一面为下一次翻转的面数即可,此时步数为 1

当 x 大于等于 6 时,由于给出的 x 为最小的分数,因此选用贪心的思想,第一次翻到 6,第二次翻到 5,第三次再翻到 6,第四次翻到 5,...,依次类推,这样一来,分数的界定区间有:[1,6],[7,11],[12,17],[18,22],[23,33],....

这样一来,当 x%(5+6)=0,即 x%11=0 时,翻转的次数必定是 x/11*2

而若 x%11!=0 时,那么其翻转次数分为两部分,一部分为前面能整除的翻转次数,一部分为后面没有整除的翻转次数

那么,前面整除的翻转次数:before=x/11*2,则后面没有整除的分数为 x-=before/2*11,之后对没有整除的分数判断即可,若 x 小于等于 6,说明只需要翻转一次到 6 朝上,反之则需要翻转两次到 5 朝上

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
int main(){
    LL x;
    scanf("%lld",&x);
    LL res;
    if(x<=6)
        res=1;
    else{
        if(x%11==0)
            res=(x/11)*2;
        else{
            LL before=(x/11)*2;
            x-=before/2*11;
            if(x<=6)
                res=before+1;
            else
                res=before+2;
        }
    }

    printf("%lld\n",res);

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值