codeforces-962-c
题意:给你一个数,问从中删除某几位数字后重新组成的数字是否是某个数的平方;
解题思路:数据小,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的更多相关文章
- Codeforces 962 /2错误 相间位置排列 堆模拟 X轴距离最小值 前向星点双连通分量求只存在在一个简单环中的边
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...
- codeforces 962 F Simple Cycles Edges
求简单环,即求点=边数的点双分量,加上判断点和边的模板即可 (简单环模板,区分与点双缩点) ; ], edgecnt, dfn[maxm], low[maxm], bcc_cnt, bccnum[ma ...
- SCC统计
Kosoraju SCC总数及记录SCC所需要的最少边情况 #include<cstdio> ; ; ][N], nxt[][N], v[][N], ed, q[N], t, vis[N] ...
- 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的环加 ...
- Codeforces 962D - Merge Equals
链接: http://codeforces.com/problemset/problem/962/D 题意: 给出一个整数序列.选择其中最小且出现两次(或以上)的数,把最左边的两个从序列中移除,然后把 ...
- codeforces 962F.simple cycle(tarjan/点双连通分量)
题目连接:http://codeforces.com/contest/962/problem/F 题目大意是定义一个simple cycle为从一个节点开始绕环走一遍能经过simple cycle内任 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- 在ASP.NET Core MVC中子类Controller拦截器要先于父类Controller拦截器执行
我们知道在ASP.NET Core MVC中Controller上的Filter拦截器是有执行顺序的,那么如果我们在有继承关系的两个Controller类上,声明同一种类型的Filter拦截器,那么是 ...
- VS2017设置主题和代码字体
从Visual Studio Marketplace下载主题插件 VS2017带有一个软件超市(Visual Studio Marketplace),可以和Eclipse一样从软件超市中下载各种插件, ...
- git pull 解决 refusing to merge unrelated histories 错误
解决办法: 1.cmd进入项目的根目录. 2.执行下面的命令:git pull origin master --allow-unrelated-histories.可以提交成功. 3.再次push.
- Python3 与 NetCore 基础语法对比(就当Python和C#基础的普及吧)
Jupyter排版:https://www.cnblogs.com/dotnetcrazy/p/9102030.html 汇总系列:https://www.cnblogs.com/dunitian/p ...
- python 跨域处理方式
因为浏览器的同源策略限制,不是同源的脚本不能操作其他源下面的资源,想操作另一个源下面的资源就属于跨域了,这里说的跨域是广义跨域,我们常说的代码中请求跨域,是狭义的跨域,即在脚本代码中向非同源域发送ht ...
- Generalized Power Method for Sparse Principal Component Analysis
目录 重点 算法 这篇文章,看的晕晕的,但是被引用了400多次了,就简单地记一笔. 这个东西,因为\(\ell_1\)范数,所以会稀疏化,当然,和\(\gamma\)有关. 重点 我想重点写的地方是下 ...
- elk之查询方式(4种)
es 在查询时, 可以指定搜索类型为下面四种: QUERY_THEN_FETCH QUERY_AND_FEATCH DFS_QUERY_THEN_FEATCH DFS_QUERY_AND_FEATCH ...
- Python_函数的有用信息、带参数的装饰器、多个装饰器装饰一个函数
函数的有用信息 代码1: def login(username, password): """ 此函数需要用户名,密码两个参数,完成的是登录的功能. :return: T ...
- MySQL的视图总结
使用下面格式创建视图: create or replace view viewName as select ..... from ...... where .... 删除视图: drop view v ...
- mysql-SQL Error: 1205, SQLState: 41000
mysql-SQL Error: 1205, SQLState: 41000——CSDN问答频道https://ask.csdn.net/questions/176492 mysql-SQL Erro ...