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
    评论
### 回答1: 这个错误提示是因为在当前的项目中找不到名为'are-we-there-yet'的模块。可能是因为该模块未安装或未正确引入。您可以尝试使用npm install命令安装该模块,或者检查代码中是否正确引入了该模块。 ### 回答2: 对于这个错误,我们先来了解下are-we-there-yet。are-we-there-yet 是一款监视工具,可以监视进度并输出进度条。它作为npm包常常被其他人所使用。 现在出现 "Error: cannot find module 'are-we-there-yet' ",意思是当前环境下找不到are-we-there-yet这个模块,导致系统无法使用它。通常情况下,出现这个错误可以有以下原因: 1. 当前项目中没有安装 are-we-there-yet,需要使用 npm install 命令安装。 2. are-we-there-yet被安装在了node_modules文件夹以外的目录里。解决方法是将它移动到当前项目的node_modules文件夹里面,或者使用 npm link 命令将其在全局位置和当前项目之间创建一个链接。 3. 如果是在项目中运行的,建议使用 npm run start 命令。如果你使用了 nodemon 或者 pm2 这些可以实现热更新的工具,建议加上--ignore参数,忽略 are-we-there-yet 目录。 以上是这个错误的可能原因和解决方法。如果你还有任何问题或者需要更详细的说明,请继续追问。 ### 回答3: 在了解这个错误之前,我们首先需要了解 Node.js 的模块系统。 Node.js 模块系统是指,让用户能够在自己的代码中使用其他开发者编写的模块。这些模块可以是 Node.js 内置的模块,也可以是第三方模块。 在 Node.js 中,可以使用 require 函数来引入模块。require 函数的参数是模块名,可以是一个文件路径或者是模块名。 在运行 Node.js 程序时,如果发现无法找到请求的模块,则会报错。其中,这个错误的形式可能是“cannot find module”或者“ModuleNotFoundError”。 回到这个特定的错误:“error: cannot find module 'are-we-there-yet'”。它意味着 Node.js 在运行中无法找到名为 'are-we-there-yet' 的模块。 这种错误通常有三种可能的原因: 1. 缺少依赖包。 在 Node.js 中使用第三方模块时,需要先将模块安装到项目中,然后才能引用它。因此,如果出现模块缺失的错误,第一件事就是检查是否将依赖包安装到项目中。 可以使用以下命令安装当前项目所需的 'are-we-there-yet' 模块: ``` npm install are-we-there-yet ``` 如果模块已安装,可以检查是否有其他相关的依赖包未安装,需要一一安装,直到解决引用问题。 2. 模块路径错误。 如果引用的模块的路径有误,则会发生这种错误。在 Node.js 中,包括绝对路径、相对路径和模块名在内的路径参数都是合法的。 如果是模块名引用错误,则需要在当前文件同级或更上一级目录中,添加一个 node_modules 目录并安装模块。 3. 模块被删除或更新。 如果引用的模块最近被删除或更新到与原来的不兼容版本,那么也可能会发生这种错误。解决方法是重新安装模块或者使用兼容的版本。 在检查这些可能原因时,需要考虑到具体的操作环境和代码上下文。只要理解了 Node.js 的模块系统的基础知识,就能轻松解决这样的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值