Educational Codeforces Round 42 (Rated for Div. 2) C

时间:2023-01-30 12:15:20
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 nn, 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 nn to make from it the square of some positive integer or report that it is impossible.

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

Input

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

Output

If it is impossible to make the square of some positive integer from nn, 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 83148314 the digits 33 and 44. After that 83148314 become equals to 8181, which is the square of the integer 99.

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

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

题意:判断x是否是一个完全平方数,如果不是,最少能删去几个数让他是完全平方数,如果有,输出删去的最少操作次数,若没有,输出-1;

思路:暴力枚举,从1开始,到sqrt(x)位置,看是否满足这个数是x的子串,如果是,存下它的操作次数与min进行比较,输出 min;

小知识点:to_string 函数,可以将一串数字转化成字符串

#include<iostream>
#include<string> using namespace std; int main()
{
string s1 = "2018.11";
int a1 = stoi(s1);
double c = stod(s1);
float d = stof(s1);
int a2 = a1 + ;
string b = to_string(a1);
b.append(" is a string"); cout << a1 <<"/"<<c<<"/"<<d<<"/"<<a2<<"/"<<b<< endl;
}

AC代码

#include <bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define low_b lower_bound
#define up_b upper_bound
#define all(v) v.begin(), v.end() using namespace std; typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll; inline void Kazakhstan(){
ios_base :: sync_with_stdio();
cin.tie(), cout.tie();
} const int N = 2e9; int main(){
Kazakhstan();
string s; cin >> s;
int mn = INT_MAX;
for(int i = ; i * i <= N; i++){
string t = to_string(i * i);
int k = ;
bool w = ;
for(int j = ; j < s.size(); j++){
if(t[k] == s[j])k++;
if(k == t.size()){
w = ;
break;
}
}
if(w){
mn = min(mn, int(s.size() - t.size()));
}
}
if(mn == INT_MAX)cout << "-1";
else cout << mn;
}

Educational Codeforces Round 42 (Rated for Div. 2) C的更多相关文章

  1. Educational Codeforces Round 42 &lpar;Rated for Div&period; 2&rpar; E&period; Byteland&comma; Berland and Disputed Cities

    http://codeforces.com/contest/962/problem/E E. Byteland, Berland and Disputed Cities time limit per ...

  2. Educational Codeforces Round 42 &lpar;Rated for Div&period; 2&rpar; D&period; Merge Equals

    http://codeforces.com/contest/962/problem/D D. Merge Equals time limit per test 2 seconds memory lim ...

  3. Educational Codeforces Round 42 &lpar;Rated for Div&period; 2&rpar;F - Simple Cycles Edges

    http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...

  4. Educational Codeforces Round 42 &lpar;Rated for Div&period; 2&rpar; B

    B. Students in Railway Carriage time limit per test 2 seconds memory limit per test 256 megabytes in ...

  5. Educational Codeforces Round 42 &lpar;Rated for Div&period; 2&rpar; A

    A. Equator time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  6. D&period; Merge Equals(from Educational Codeforces Round 42 &lpar;Rated for Div&period; 2&rpar;)

    模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include &lt ...

  7. Educational Codeforces Round 42 &lpar;Rated for Div&period; 2&rpar;

    A. Equator(模拟) 找权值的中位数,直接模拟.. 代码写的好丑qwq.. #include<cstdio> #include<cstring> #include&lt ...

  8. C&Tab; Make a Square Educational Codeforces Round 42 &lpar;Rated for Div&period; 2&rpar; &lpar;暴力枚举,字符串匹配&rpar;

    C. Make a Square time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...

  9. D&Tab; Merge Equals Educational Codeforces Round 42 &lpar;Rated for Div&period; 2&rpar; (STL )

    D. Merge Equals time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...

随机推荐

  1. oracle基本操作

    登入oraclesqlplus / as sysdba启动oraclestartup停止oracleshutdown 创建新用户create user username identified by p ...

  2. 【CSS3】---嵌入字体&commat;font-face

    @font-face能够加载服务器端的字体文件,让浏览器端可以显示用户电脑里没有安装的字体. 语法: @font-face { font-family : 字体名称; src : 字体文件在服务器上的 ...

  3. ip、数字的互转

    # ip ==> 数字 >>> ip2num = lambda x:sum([256**j*int(i) for j,i in enumerate(x.split('.')[: ...

  4. I&sol;O概述和审查操作

    I/O流量可表示非常多不同种类的输入源和输出目的地.它包含一个简单的字节流,基本数据(int.boolean.double等待),本地化字符,和对象.仅是简单地传递数据,另一些流能够操作和转换数据 不 ...

  5. Flex上传文件报&OpenCurlyDoubleQuote;Error &num;2038”

    1.错误描述 ioerror: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 t ...

  6. 1&period;2浅谈Spring-Spring结构

    时隔很多天的我又回来....最近发展了一下自己的爱好,所以拖了很长时间. 前面我们从概念性上分析了spring的特性 这里我们附上Spring框架的结构图 我们简单的来说一些这个框架图 我们从下往上看 ...

  7. ubuntu下安装&sol;卸载vmware虚拟机

    1.下载vmware(官网下载试用版,试用版输入序列号后即为专业版,序列号网上搜,很多) 2.下载后安装(命令行) 1)cd进你下载的位置 1.1)下载的文件名字为:VMware-Workstatio ...

  8. thinkphp5&period;0 实现图片验证效果且能点击图片刷新图片

    思路与文件上传相同,只是验证码一个方法: <img src="{:captcha_src()}" /> 后台文件:app\ceshi\yam <?php name ...

  9. webService开发&lpar;JDK版&rpar;

    最近做社保查询的东西,然而这个是三个公司一起做的,需要调其他公司的接口,他们公司用了webService这个当年比较流行的技术,于是乎就研究了一下这个webService. HTTP协议 + XML方 ...

  10. selenium3&plus;python自动化50-环境搭建(firefox)

    前言 有不少小伙伴在安装selenium环境后启动firefox报错,因为现在selenium升级到3.0了,跟2.0的版本还有有一点区别的. 安装环境过程中主要会遇到三个坑: 1.'geckodri ...