Educational Codeforces Round 42 (Rated for Div. 2) C
2 seconds
256 megabytes
standard input
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.
The first line contains a single integer nn (1≤n≤2⋅1091≤n≤2⋅109). The number is given without leading zeroes.
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.
8314
2
625
0
333
-1
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的更多相关文章
- Educational Codeforces Round 42 (Rated for Div. 2) E. Byteland, Berland and Disputed Cities
http://codeforces.com/contest/962/problem/E E. Byteland, Berland and Disputed Cities time limit per ...
- Educational Codeforces Round 42 (Rated for Div. 2) D. Merge Equals
http://codeforces.com/contest/962/problem/D D. Merge Equals time limit per test 2 seconds memory lim ...
- Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges
http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...
- Educational Codeforces Round 42 (Rated for Div. 2) B
B. Students in Railway Carriage time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Educational Codeforces Round 42 (Rated for Div. 2) A
A. Equator time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))
模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include < ...
- Educational Codeforces Round 42 (Rated for Div. 2)
A. Equator(模拟) 找权值的中位数,直接模拟.. 代码写的好丑qwq.. #include<cstdio> #include<cstring> #include< ...
- C Make a Square Educational Codeforces Round 42 (Rated for Div. 2) (暴力枚举,字符串匹配)
C. Make a Square time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
- D Merge Equals Educational Codeforces Round 42 (Rated for Div. 2) (STL )
D. Merge Equals time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
随机推荐
- 路由器基础配置之rip
我们将以上面的拓扑图进行实验,用rip协议来进行实验,目的是实现三台不同网段的pc机之间实现互相通信 首先为pc机配置好ip地址和网关,配置完IP地址后在配置路由器 router1: enable 进 ...
- Apache+Tomcat+jk windows环境下的集群部署
记一次在Windows服务器上搭建apatch+tomcat+jk的集群搭建过程,其中也遇到了很多问题,总结一下. 一.准备工作 1.apache-tomcat-7.0.88 2.Apche http ...
- MySQL的隐式类型转换整理总结
当我们对不同类型的值进行比较的时候,为了使得这些数值「可比较」(也可以称为类型的兼容性),MySQL会做一些隐式转化(Implicit type conversion). 比如下面的例子: 1 2 ...
- C语言数组篇(五)多级指针和二维数组指针的区别
多级指针 以二级指针为例 二级指针的由来是 指针数组 的指针形式. int *p[10] 读取的顺序是 p[] --> 10个空间的数组 * p[] --> 这10个空间的数组里面存放 ...
- 图像的模糊-opencv
调用两个API,一个是均值模糊,一个是高斯模糊.如下所示: #include<opencv2/opencv.hpp> #include<iostream> using name ...
- 笔记-ORM-sqlalchemy
笔记-ORM-sqlalchemy 1. ORM 1.1. ORM框架简介 对象-关系映射(Object/Relation Mapping,简称ORM),是随着面向对象的软件开发方法发 ...
- 关于Android SDK无法更新的解决办法
最新摆弄PhoneGap打包,所以需要安卓的环境,配置后,sdk更新实在是在慢了,上网找了一下,可能被强了,所有总结如下办法,最后弄好了,跟大家分享一下 具体步骤:1:打开SDK Manager.ex ...
- div嵌套img高度不相同
div中嵌套img,如果div里嵌套一个img元素且div的高度是由img的高度来撑开,那么div的高度总会比img的高度多3px. 可以明显看到div实际高度高出img高度3px.为了解决此问题,我 ...
- ElasticSearch学习笔记(四)-- 分布式
1. 分布式介绍及cerebro cerebro插件 点击release下载 解压运行 访问9000端口,连接es的9200端口 2. 构建集群 新增一个节点 3. 副本与分片 再加入一个节点 4. ...
- 【情人节礼物】纯js脚本打造精美3D玫瑰
情人节就要来临了,这是用代码做出的玫瑰花,这才是程序员送给女友的最好情人节礼物...(提示:在不同浏览器下观看效果.速度会有很大的不同) 代码如下: <!doctype html> < ...