codeforces 962 C. Make a Square

Mid-360与FAST-LIO2实战:从硬件配置到高精度点云建图全流程 激光雷达SLAM建图是机器人与测绘领域的关键技术,而固态激光雷达与紧耦合激光惯性里程计的组合正在成为实时高精度建图的主流方案。非重复扫描方式使雷达在积分时间内获得超高点云覆盖率,配合基于全量点云配准的迭代卡尔曼滤波框架,能在室内外复杂场景中稳定输出厘米级点云地图。其中ikd-Tree增量式索引结构解决了海量点云的实时处理瓶颈,IMU紧耦合则保证了快速运动下的位姿鲁棒性。本文从硬件选型、驱动配置、参数调优到点云后处理,系统梳理了Mid-360与FAST-LIO2的完整落地流程,并给出了常见故障排查与工程化避坑 阅读详情

Description

You are given a positive integer n , written without leading zeroes (for example, the number 04 is incorrect).

In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.

Determine the minimum number of operations that you need to consistently apply to the given integer n to make from it the square of some positive integer or report that it is impossible.

An integer x is the square of some positive integer if and only if x = y2 for some positive integer y .

Input

The first line contains a single integer n ( 1≤n≤2⋅10 9 ). The number is given without leading zeroes.

Output

If it is impossible to make the square of some positive integer from n, print -1. In the other case, print the minimal number of operations required to do it.

Examples

Input
8314
Output
2

Input
625
Output
0

Input
333
Output
-1

Note

In the first example we should delete from 8314 the digits 3 and 4. After that 8314 become equals to 81 , which is the square of the integer 9 .

In the second example the given 625 is the square of the integer 25 , so you should not delete anything.

In the third example it is impossible to make the square from 333 , so the answer is −1 .


参考了下面的博客

https://www.cnblogs.com/a249189046/p/8821300.html

题意:给一个整数,每次删除一个位,要求删除后的首位不能是0,问多少次操作以后变为平方数。
思路:百度了一下开方函数的复杂度,没有看的很懂但是其中有一个说法是:

  • 取对数->乘0.5->取指数

其中第一步和第三步可以用硬件实现,这样下来复杂度就是O(1)的,所以用开方函数来检查一个整数是否是平方数是可以的。
由于输入最多有10位,搜索起来最坏的情况要做10!次,这是不能接受的,这是由于重复搜索导致的,所以使用set记录搜索过的数字,把次数降到了2^10次(巨大的优化)

#include<stdio.h>
#include<math.h>
#include<queue>
#include<set>
using std::queue;
using std::set;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mabs(x) ((x)>0?(x):(0-(x)))
#define N_max 44722
int n;
int a10[N_max];
queue<int> a;
set<int> b;
int r(int x, int i) { 
    return x / a10[i + 1]*a10[i] + x%a10[i]; 
}

int bfs(int len) {
    int next,temp;
    for (int k = 0; k < len; ++k) {
        int t = a.size(), x;
        for (int i = 0; i < t; ++i) {
            //遍历上一层产生的数
            x = a.front(); a.pop();
            for (int q = 0; q < len - k; ++q) {//搜索去掉每一位后产生的数
                if (q>0&&q ==len-k-1 && ((x%a10[q]) / a10[q - 1]) == 0)
                //判断是否在首位以及同时第二位是否是0
                    continue;
                next = r(x, q);//生成下一个数
                if (next <= 0)continue;//特判
                //利用set检查该数是否出现过
                if (b.find(next) == b.end())b.insert(next);
                else { continue; }
                //利用sqrt检查该数是否是平方数
                temp = sqrt(next);
                if (temp*temp == next)
                    return k;
                //入队列,为下一层bfs做准备
                a.push(next);
            }
        }
    }
}
int main() {
    scanf("%d", &n);

    int len = 0,temp;
    temp = sqrt(n);
    if (temp*temp == n) {
        printf("0"); return 0;
    }
    //计算位数,保存在len里
    for (temp = n; temp > 0; ++len)temp /= 10;
    //计算10, 100, 1000,...方便取模
    a10[0] = 1;
    for (int i = 1; i < 15; ++i) {
        a10[i] = a10[i - 1] * 10;
    }
    a.push(n);
    temp = 1 + bfs(len);
    if(temp<len)printf("%d",temp);
    else printf("-1");
}
直流有刷电机控制 - 认识电机(一) 电机控制学习 阅读详情

相关推荐

5分钟搞定!用L型匹配电路优化窄带天线性能(附Smith圆图实操)

本文针对窄带天线阻抗匹配难题,提供了一套5分钟快速解决方案。通过详解L型匹配电路的核心原理,并结合Smith圆图这一射频工程师的“瑞士军刀”,手把手指导如何选择拓扑、计算元件值并进行实际调试,旨在帮助硬件工程师高效优化天线性能,实现最大功率传输。

yyy34的博客 443

Codeforces Round 962 (Div. 3)(A~E)

这场div.3难度比以前更大一些,一道C题想了半天都想不出来,导致这场比赛直接寄了·····,打的非常烂(不如直接摆烂睡觉:(

wh233z的博客 1529

历年安徽省省赛AHOI初中组考点分类汇总考点分类汇总

持续更新中.....

weixin_42358969的博客 818

Codeforces Round 962 (Div. 3)

总结:ABC秒过,D有点难评了,E优化很妙。

MenghuanL的博客 900

华为OD面试八股文嵌入式C语言基础问题及答案(一)

本文总结了C语言编程中的10个关键知识点:1.宏定义MIN的实现方法;2.嵌入式无限循环的两种写法;3.变量a的8种不同定义方式;4.static关键字的三种作用;5.const关键字的含义和使用场景;6.volatile关键字的含义及三个应用实例;7.变量存储位置(栈区、静态区、堆区);8.32位系统指针位数;9.局部与全局变量重名规则;10.引用与指针的三点区别。这些内容涵盖了宏定义、变量声明、存储类别、指针等C语言核心概念,对嵌入式开发和系统编程具有重要参考价值。

m0_50382756的博客 160

history 历史命令记录功能如何防坏人(高级)

在 Linux 下面可以使用 history 命令查看用户的所有历史操作,同时 shell 命令操作记录默认保存在用户目录的 .bash_history 文件中。通过这个文件可以查询 shell 命令的执行历史,有助于运维人员进行系统审计和问题排查,同时在服务器遭受黑客攻击后,也可以查询黑客登录服务器的历史命令操作。但是黑客在入侵后,为了抹除痕迹,会删除 .bash_history 文件,这个就需...

墨痕诉清风的博客 1655

Codeforces Round 962 (Div. 3) Problem C

Codeforces Round 962 (Div. 3) Problem C

2401_86351320的博客 483

【Ellisys】【使用技巧】【二】

支持所有常见的编码器和协议实时播放或保存(无线和HCI)循环播放导出与其他视图协同(OverView 和 Spectrum)可以通过下面的位置看 重传的包。

奔跑吧 android 的博客 135

Codeforces Round 962 (Div. 3) ABCDEF(思路+代码)

​。

qq_66608435的博客 532

使用 Simulink + Simscape Electrical 对 级联H桥多电平整流器并网功率分配 进行建模与仿真

摘要:本文详细介绍了基于Simulink对级联H桥(CHB)多电平整流器并网功率分配进行建模的方法。内容包括系统组成、功率分配意义、Simulink建模流程、PWM控制策略实现、功率分配算法设计以及仿真分析。重点阐述了主电路搭建、双环控制结构(外环功率分配+内环电流控制)和载波层叠PWM调制技术,并提供了功率分配算法示例。通过优化参数和控制算法,可提升系统性能。该建模方法为电力电子变换器和新能源并网系统研究提供了有效工具。

amy_mhd的博客 251

duilib 之 事件--bubbled冒泡事件应用、通用点击事件、进入离开事件、XML样式中直接添加事件

1. box 绑定点击事件 ui::Box *pSmallVideoBox = (ui::Box*)FindControl(L"rightBox"); if (pSmallVideoBox) { auto SwitchVideo = [this](ui::EventArgs* param){ m_bSecScreenIsScale = m_bMainScre...

目前打算换一个工作,有招聘windows c++方向的也欢迎联系,北京、济南 最好 972

Codeforces962 C. Make a Square

You are given a positive integer ????, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros. Determine t

tomjobs的博客 543

MicroCap声学仿真介绍(六)-入耳式耳机仿真

从上图可以看出,后腔开了泄声孔后,振膜的最大位移从4.8um提升到了10um,振膜位移增加了一倍。在实际应用中,一般耳机的前腔和后腔都需要开泄声孔,开孔的大小和调音网布的阻尼需要根据客户的要求以及仿真的结果进行权衡选择。接着在主界面放置电阻、电感、电容,电阻值为Rms,电感值为Mms,电容值为Cms,如下图。假设后腔泄声孔的直径为1.2mm,宽度为0.3mm,对应调音网的阻抗为5.5e8欧姆。假设前腔泄声孔的直径为1.2mm,宽度为0.3mm,对应调音网的阻抗为5.5e8欧姆。

山无忧的博客 1800

CodeForces 962C Make a Square

       题意是给你一个数字,然后问最少删掉几个数字能让这个数字变成一个完全平方数。可以枚举1-n的值的平方,然后转成字符串去操作。AC代码:#include &lt;iostream&gt; #include &lt;cstdio&gt; #include &lt;cstring&gt; using namespace std; int n,num1,num2; string str1,st...

Charles_Zaqdt的博客 453

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

CodeForces 962C - Make a Square

题目链接:http://codeforces.com/contest/962/problem/C

cjc7373的博客 634

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

codeforces 962-C. Make a Square(暴力)

http://codeforces.com/problemset/problem/962/C 题目大意: 给出一个个数,要求可以删除任意个任意数位上的数,是否存在一个最少的删除,使得操作之后的数为一个平方数。要求操作后的数不能有前导零。输出最少删除的个数。 解题思路: 因为数值只有9位,因此可以暴力枚举2^len,其中len为数的长度。考虑前导零的特殊情况即可; #...

HJ 599

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

codeforces 962C Make a Square

题目链接:http://codeforces.com/contest/962/problem/C 题意:给你一个数字n (n<=2e9)没有前导0。现在需要你删除一些数字,也可以不删除,使得剩下的数是平方数。删除后得到的数字不存在前导0。输出删除最少的位数,不存在输出-1. 分析:看到n的范围。一共最多也就10位,直接暴力枚举每一种删除情况,然后再判断每种情况是否为平方数,取min就可以...

weixin_34342992的博客 163

CodeForces - 962C Make a Square (dfs)

  水题 深搜即可 但要注意前导0的问题   #include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; #include&lt;string.h&gt; #include&lt;math.h&gt; #include&lt;queue&gt; #include&lt;map&gt; #include&lt;algorithm&gt; #inclu

qmhna_的博客 1098

Codeforces-962C-Make a Square(暴力二进制枚举)

C. Make a Squaretime limit per test:2 secondsmemory limit per test:256 megabytesinput:standard inputoutput:standard outputYou are given a positive integer n, written without leading zeroes (for exampl...

wust_cyh 663

Codeforces 962C Make a Square(bfs)

题目链接:Make a Square 题意 给定一个不包含前导零的正整数 nnn,要求删除最少的数字位,使得最终剩下的数字不包含前导零且它是一个完全平方数,或者判断这是无法实现的。 输入 输入只包含一个整数 n&nbsp;(1≤n≤2×109)n&nbsp;(1≤n≤2×109)n~(1\leq n\leq2\times10^9)。 输出 如果无法实现,则...

Dmaxiya 521

Codeforces Round 962

Codeforces Round 962

青少年趣味编程 728

codeforces C. Make a Square

题目网址:http://codeforces.com/problemset/problem/962/CC. Make a Squaretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a positive intege...

Amo丶 319

Codeforces Round 962 (Div3) A-C题解

题目大意:给定你两个字符串 每次给定一个范围l

2301_79967286的博客 1148

Codeforces Round 962 (Div. 3) a~d题解

Codeforces Round 962 (Div. 3)a~d的思路题解

2402_82472978的博客 736

Codeforces 962E Byteland, Berland and Disputed Cities [想法]

Codeforces 962E Byteland, Berland and Disputed Cities [想法]

ACTerminate的博客 851
上一篇: codeforces 913 D. Too Easy Problems
下一篇: codeforces 962 D. Merge Equals
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值