博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Educational Codeforces Round 42 C. Make a Square(字符串操作)
阅读量:5162 次
发布时间:2019-06-13

本文共 2091 字,大约阅读时间需要 6 分钟。

C. Make a Square

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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⋅109

). 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
Copy

8314

Output

Copy

2

Input

Copy

625

Output

Copy

0

Input

Copy

333

Output

Copy

-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.

比赛的时候想着将数字看成字符串的,但是没有想清楚就写了,最后终测还是挂掉了.

看成字符串处理,可以不考虑前缀零.然后转换成数字判断是否满足条件即可

#include
#define ll long long#define inf 0x3f3f3f3f#define pb push_back#define rep(i,a,b) for(int i=a;i
=a;i--)using namespace std;const int N=2e5+100;ll arr[N];vector
G;struct node{ string x; int d;};int main(){ string str; cin>>str; node t={str,0}; map
mp; map
mp1; for(ll i=1;i<1e5;i++) { mp[i*i]=1; } queue
q; q.push(t); mp1[str]=1; while(!q.empty()) { t=q.front(); q.pop(); string s=t.x; int sum=(int)s[0]-'0'; for(int i=1;i

转载于:https://www.cnblogs.com/ffgcc/p/10546450.html

你可能感兴趣的文章
CentOS7 设置开机自启
查看>>
数塔-动态规划
查看>>
HDU 1210 Eddy's 洗牌问题(找规律,数学)
查看>>
[MySQL5.6] 最近对group commit的小优化
查看>>
CentOS工作内容(六)双网卡带宽绑定bind teaming
查看>>
android 签名验证防止重打包
查看>>
.Net-using-Class:MemoryCache 类
查看>>
python学习之day5,装饰器,生成器,迭代器,json,pickle
查看>>
day7_subprocess模块和面向对象,反射
查看>>
问题-[DelphiXE7]新建的安桌模拟器运行程序闪退
查看>>
用二进制进行权限管理
查看>>
嵌入式音频软件的架构【转】
查看>>
PHP-5.6.22安装
查看>>
zoom和transform:scale的区别
查看>>
POJ1741 经典树分治
查看>>
POJ 1678 I Love this Game!
查看>>
【Alpha 冲刺】 5/12
查看>>
git fetch和git pull的区别
查看>>
不挣扎了,MVC验证错误信息汇总是酱紫的
查看>>
用selenium启动IE时报错
查看>>