版权声明:本文为博主原创文章,未经博主同意不得转载。 https://blog.csdn.net/qq574857122/article/details/25166611

题目链接:点击打开链接

题意:rt

思路:从最低位開始构造,若x位的平方数是自身则继续构造。

mark:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
#include<string>
#include<ctime>
using namespace std;
#define N 555
int n;
int a[N];
vector<string>ans[N];
void dfs(int pos,int *s)
{
int i,j;
if(pos==n)
{
string tmp="";
for(i=n-1;i>=0;i--)
{
tmp+=(char)(a[i]+'0');
}
ans[n].push_back(tmp);
return;
}
int c[N];
for(i=0;i<=9;i++)
{
if(pos==n-1&&i==0)continue;
if(pos==0&&(i!=0&&i!=5&&i!=6))continue;
int g = a[0]*i*2+s[pos];
if(pos==0)g-=a[0]*i;
if(pos==0||(pos>0&&g%10==i))
{
int M = min(n,500);
for(j=0;j<=M;j++)
c[j]=s[j];
a[pos]=i;
int k=0;
for(j=pos;j<=n;j++)
{
int tmp = a[k]*i+c[j];
if(pos>0&&k<=pos-1)tmp+=a[k]*i;
c[j]=tmp%10;
c[j+1]+=tmp/10;
k++;
}
dfs(pos+1,c);
a[pos]=0;
}
}
}
int b[N];
int main()
{
int i,j,t;
for(i=1;i<=500;i++)
ans[i].clear();
memset(b,0,sizeof(b));
for(i=1;i<=500;i++)
{ n=i;
dfs(0,b);
sort(ans[i].begin(),ans[i].end());
}
scanf("%d",&t);
int cas=0;
while(t--)
{
scanf("%d",&n);
printf("Case #%d:",++cas);
if(n==1)printf(" 0 1");
if(n!=1&&ans[n].size()==0)
{
printf("Impossible");
}
for(i=0;i<ans[n].size();i++)
{
cout<<" "<<ans[n][i];
}
puts("");
}
return 0;
}

Uva 12009 平方数尾数与自身同样 dfs 构造的更多相关文章

  1. Uva 11542 乘积是平方数

    题目链接:http://vjudge.net/contest/142484#problem/A 这个题目也是2016年CCPC网赛上面的题目,当时我是不会做的,但是大牛们都知道这是一个原题,最后给一队 ...

  2. 人活着系列之平方数 分类: sdutOJ 2015-06-22 17:10 7人阅读 评论(0) 收藏

    人活着系列之平方数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 偶然和必然?命运与意志?生与死?理性与情感?价值与非价值?在&quo ...

  3. 洛谷P1206 [USACO1.2]回文平方数 Palindromic Squares

    P1206 [USACO1.2]回文平方数 Palindromic Squares 271通过 501提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 暂时没有 ...

  4. Project Euler 92:Square digit chains 平方数字链

    题目 Square digit chains A number chain is created by continuously adding the square of the digits in ...

  5. Project Euler 98:Anagramic squares 重排平方数

    Anagramic squares By replacing each of the letters in the word CARE with 1, 2, 9, and 6 respectively ...

  6. BZOJ2440(全然平方数)二分+莫比乌斯容斥

    题意:全然平方数是指含有平方数因子的数.求第ki个非全然平方数. 解法:比較明显的二分,getsum(int middle)求1-middle有多少个非全然平方数,然后二分.求1-middle的非全然 ...

  7. uva 12009 - Avaricious Maryanna(暴力)

    option=com_onlinejudge&Itemid=8&category=516&page=show_problem&problem=3160" ta ...

  8. UVA 12009 - Avaricious Maryanna(数论)

    UVA 12009 - Avaricious Maryanna 题目链接 题意:给定一个n.求出n个数位组成的数字x,x^2的前面|x|位为x 思路:自己先暴力打了前几组数据,发现除了1中有0和1以外 ...

  9. [LeetCode] Sum of Square Numbers 平方数之和

    Given a non-negative integer c, your task is to decide whether there're two integers a and b such th ...

随机推荐

  1. 字符串(2)KMP算法

    给你两个字符串a(len[a]=n),b(len[b]=m),问b是否是a的子串,并且统计b在a中的出现次数,如果我们枚举a从什么位置与匹配,并且验证是否匹配,那么时间复杂度O(nm), 而n和m的范 ...

  2. 解决微信小程序Video 某些属性设置不起作用问题

    <video controls="{{false}}" autoplay="{{true}}"></video> 设置属性务必要使用{{ ...

  3. 项目启动,main函数之前的代码执行两次 restartedMain

    https://blog.csdn.net/qq_35981283/article/details/78925146

  4. git更新Activemq在远程github上指定版本的源码步骤

    第一步:根据地址克隆源码 (activemq-5.9) $  git  clone   https://github.com/apache/activemq.git 第二步:查看远程源码的版本清单 ( ...

  5. PID控制算法的简单分析和仿真!

    PID算法简单剖析如下: 1.首先我们来看一下PID系统的基本组成模块: 如图所示,图中相关参数的表示如下: r(t):系统实际上需要的输出值,这是一个标准值,在我们设定了之后让这个系统去逼近的一个值 ...

  6. rpm 安装、卸载软件命令 ——以nginx为例

    1.安装 命令:rpm    -ivh    nginx-1.14.0-1.el7_4.ngx.x86_64.rpm 2.查看安装结果 命令:rpm   -qa  | grep  nginx 3.升级 ...

  7. selenium webdriver 如何添加cookie

    一. webdriver中常用的cookie方法 webdriver中提供了操作cookie的相关方法: get_cookies()                  获得cookie信息 add_c ...

  8. 【Linux】-- Linux上java运行环境的配置(JDK+TOMCAT)

    1.JDK安装 安装之前首先要查询软件是否存可以直接使用yum安装 yum search java | grep open 选择需要的版本安装 注意:*星号代表下载该版本的所有文件,不能少. 验证是否 ...

  9. webpack报错需要合适的loader

    以前做vue项目都好好的,最近做react,公共配置感觉加个jsx就可以了吧,然而不是这样的. 一.问题描述 You may need an appropriate loader to handle ...

  10. three.js 使用DragControls.js 拖动元素

    首先,引入js文件: <script type="text/javascript" src="./path/to/DragControls.js"> ...