题意:给你一个数,问从中删除某几位数字后重新组成的数字是否是某个数的平方;

解题思路:数据小,dfs直接搜,每位数只有两种选择,要或者不要

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
ll a[20];
int ans=999999;
int cnt;
void dfs(int step,ll x,int len)
{
if(step>cnt)
return;
int m=sqrt(x);
int tx=x;
if(m*m==x&&x!=0)
{
int t=0;
while(tx)
{
t++;
tx=tx/10;
}
ans=min(ans,cnt-t);
}
dfs(step+1,x,len);
dfs(step+1,x+a[step+1]*pow(10,len),len+1);
}
int main()
{
ll n;
ll z;
cnt=0;
cin>>n;
z=n;
int q=sqrt(n);
if(q*q==n)
cout<<"0\n";
else
{ while(z)
{
cnt++;
a[cnt]=z%10;
z=z/10;
}
dfs(0,0,0);
if(ans==999999)
cout<<"-1\n";
else
cout<<ans<<endl;
}
}

  

codeforces-962-c的更多相关文章

  1. Codeforces 962 /2错误 相间位置排列 堆模拟 X轴距离最小值 前向星点双连通分量求只存在在一个简单环中的边

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  2. codeforces 962 F Simple Cycles Edges

    求简单环,即求点=边数的点双分量,加上判断点和边的模板即可 (简单环模板,区分与点双缩点) ; ], edgecnt, dfn[maxm], low[maxm], bcc_cnt, bccnum[ma ...

  3. SCC统计

    Kosoraju SCC总数及记录SCC所需要的最少边情况 #include<cstdio> ; ; ][N], nxt[][N], v[][N], ed, q[N], t, vis[N] ...

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

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

  6. Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges

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

  7. Codeforces 962D - Merge Equals

    链接: http://codeforces.com/problemset/problem/962/D 题意: 给出一个整数序列.选择其中最小且出现两次(或以上)的数,把最左边的两个从序列中移除,然后把 ...

  8. codeforces 962F.simple cycle(tarjan/点双连通分量)

    题目连接:http://codeforces.com/contest/962/problem/F 题目大意是定义一个simple cycle为从一个节点开始绕环走一遍能经过simple cycle内任 ...

  9. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  10. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. leetcode 4:Median of Two Sorted Arrays

    public double FindMedianSortedArrays(int[] nums1, int[] nums2) { int t=nums1.Length+nums2.Length; in ...

  2. 【vue】vue-router跳转路径url多种格式

    1.形如  http://localhost:8080/#/book?id=**** ①路由配置 ②路由定向链接,以query传参id 另外,获取query传递的参数id用  this.$route. ...

  3. ML.NET 示例:深度学习之集成TensorFlow

    写在前面 准备近期将微软的machinelearning-samples翻译成中文,水平有限,如有错漏,请大家多多指正. 如果有朋友对此感兴趣,可以加入我:https://github.com/fei ...

  4. Appium-实现手势密码登陆

    前言: 前几天有人问我,手势登陆如何做?于是我找了一个APP试了试,所以本文来总结使用Python+Appium来实现手势密码登陆APP. 环境: MacOS:10.13.4 Appium-deskt ...

  5. 广播频道-BroadcastChannel

    BroadcastChannel,就字面意思来言,叫做“广播频道”,官方文档说,该API是用于同源不同页面之间完成通信的功能. 1. 概况 它与window.postMessage的区别就是,Broa ...

  6. Final Destination II -- 矩阵快速幂模板题

    求f[n]=f[n-1]+f[n-2]+f[n-3] 我们知道 f[n] f[n-1] f[n-2]         f[n-1]  f[n-2]  f[n-3]         1    1    ...

  7. myeclipse使用hibernate5框架load延迟装载对象报错_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy

    jar包问题,将hibernate-core-5.0.12.Final.jar删除,换为hibernate-core-4.2.3.final.jar搞定.注意项目运行过后可能删不掉jar包,只需关闭m ...

  8. 用C# BigInteger实现的BigDecimal类,终于可以直接做四则运算了。

    https://code.google.com/p/dotnet-big-decimal/ 这是个BigDecimal类的开源项目,支持Operators +, - and *. 俺给改了改,加上了除 ...

  9. ES5中文分词(IK)

    ElasticSearch5中文分词(IK) ElasticSearch安装 官网:https://www.elastic.co 1.ElasticSearch安装 1.1.下载安装公共密钥 rpm ...

  10. Error: [WinError 10013] 以一种访问权限不允许的方式做了一个访问套接字的尝试

    近来发现两个问题: 1.jenkins设置邮箱时邮件发送测试不成功,之前是成功的: 2.启动python服务时,使用8000端口报错,但是用其他端口可用: 百度了一下,原来是端口占用的问题,可用如下方 ...