当前位置:网站首页>(2022牛客多校四)K-NIO‘s Sword(思维)
(2022牛客多校四)K-NIO‘s Sword(思维)
2022-08-01 04:47:00 【AC__dream】
题目:

样例输入:
4
样例输出:
4题意:玩家初始有一把攻击力为0的剑,需要依次击杀n个敌人,仅当攻击力模n与i同余才能击杀第i个敌人。而且只能从前往后击杀敌人,也就是说,击杀编号为i的敌人前一定要先击杀编号为i-1的敌人。玩家可以升级剑,每次升级就是将剑的当前攻击力乘以10再加上0~9的一个数,问要想击杀所有的敌人至少要几次升级。
分析:假如我们当前已经击杀了第i个敌人,也就是说现在我们的剑的攻击力ai=k*n+i,我们可以直接将其等价为i,因为比如我们对剑升级了x次,那么剑的攻击力就变为(k*n+i)*10^x+y(y为一个x位数),等价于k*n*10^x+(i*10^x+y),那么在modn意义下有没有前面的k*n是没有什么区别的,也就是说,我们直接把击杀第i个敌人后的攻击力看成i即可。现在我们击杀了第i个敌人,也就是说我们现在剑的攻击力是i,那么假设我们升级x后可以击杀第i+1个敌人,也就是说存在一个x位数y使得(i*10^x+y)%n=(i+1)%n,那么就等价于(i+1-i*10^x)%n=y%n,由于y是一个任意的x位数,那么我们只要判断一下(i+1-i*10^x)%n是不是一个x位数即可(可以有前导0),判断的复杂度就是O(1)的,由于n的位数最大是6,所以我们最多需要升级的次数也是6,所以直接暴力判断即可:
需要注意的一个点是n=1时需要特判!
下面是代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
const int N=1e6+10;
int p10[15]={1,10,100,1000,10000,100000,1000000,10000000};
int cnt(long long x)
{
int ans=0;
while(x)
{
ans++;
x/=10;
}
return ans;
}
int main()
{
int n;
cin>>n;
if(n==1)
{
printf("0");
return 0;
}
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=6;j++)
{
long long x=((i+1-1ll*i*p10[j])%n+n)%n;
if(cnt(x)<=j)
{
ans+=j;
break;
}
}
}
printf("%d",ans);
return 0;
}
边栏推荐
- 【愚公系列】2022年07月 .NET架构班 085-微服务专题 Abp vNext微服务网关
- PMP 相关方管理必背总结
- MySQL3
- Mysql基础篇(约束)
- JS new fun(); class and instance JS is based on object language Can only act as a class by writing constructors
- 律师解读 | 枪炮还是玫瑰?从大厂之争谈元宇宙互操作性
- IJCAI2022 | Hybrid Probabilistic Reasoning with Algebraic and Logical Constraints
- Typescript22 - interface inheritance
- safari浏览器怎么导入书签
- Mysql基础篇(Mysql数据类型)
猜你喜欢

Pyspark Machine Learning: Vectors and Common Operations

出现Command ‘vim‘ is available in the following places,vim: command not found等解决方法

MySQL4

7月编程排行榜来啦!这次有何新变化?

UE4 模型OnClick事件不生效的两种原因

Unknown Bounded Array

typescript28 - value of enumeration type and data enumeration

Typescript20 - interface

Passive anti-islanding-UVP/OVP and UFP/OFP passive anti-islanding model simulation based on simulink

This article takes you to understand the past and present of Mimir, Grafana's latest open source project
随机推荐
The Principle Of Percona Toolkit Nibble Algorithm
数据比对功能调研总结
Li Chi's work and life summary in July 2022
The difference between scheduleWithFixedDelay and scheduleAtFixedRate
FFmpeg 搭建本地屏幕录制环境
Game Theory (Depu) and Sun Tzu's Art of War (42/100)
出现Command ‘vim‘ is available in the following places,vim: command not found等解决方法
Invalid classes inferred from unique values of `y`. Expected: [0 1 2], got [1 2 3]
Error using ts-node
Dynamic Programming 01 Backpack
解决ffmpeg使用screen-capture-recorder录屏,有屏幕缩放的情况下录不全的问题
云服务器下载安装mongo数据库并远程连接详细图文版本(全)
【云原生之kubernetes实战】kubernetes集群的检测工具——popeye
How to promote new products online?
今日睡眠质量记录68分
PAT乙级 1002 写出这个数
Advice given by experts with four years of development experience in Flutter tutorial
7月编程排行榜来啦!这次有何新变化?
25. Have you been asked these three common interview questions?
Unity's primary method for implementing PlanarReflection under the BuildIn rendering pipeline