版权声明:本文为博主原创文章,未经博主同意不得转载。 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. 【python】命令行神器 Click 简明笔记

    全文拷贝自 命令行神器 Click 简明笔记 Click Click 是用 Python 写的一个第三方模块,用于快速创建命令行.我们知道,Python 内置了一个 Argparse 的标准库用于创建 ...

  2. Zombie Scanning

    1.theree -way handshake A TCP SYN packet is sent from the device that wishes to establish a connecti ...

  3. C# .Net 中字典Dictionary<TKey,TValue>泛型类 学习浅谈

    一.综述: Dictionary<TKey,TValue>是在 .NET Framework 2.0 版中是新增的.表示键值对的集合,Dictionary<TKey,TValue&g ...

  4. Kali linux2.0里Metasploit的postgresql selected, no connection问题解决

    说在前面的话 1.在kali中metasploit默认使用postgresql作为它的数据库: 想要开启metasploit服务首先得打开postgresql数据库, 命令如下:(或者:/etc/in ...

  5. django---不使用view,直接从Url转到html

    这个在使用公告页时,就很方便. 因为无需要经过数据库,视图. 直接使用文字. https://docs.djangoproject.com/en/2.1/topics/class-based-view ...

  6. spring boot 2.0 neo4j 使用

    参考文档 官方文档 http://spring.io/projects/spring-data-neo4j#learn https://docs.spring.io/spring-data/neo4j ...

  7. ExtJS5搭建MVVM框架

    概述 · ExtJs5能够搭建Js的MVC框架,通过配置路由能够通过左边树形菜单导航到所需的页面,效果如下: 搭建JS框架 新建home.htm页面作为ExtJs加载的主体页面,页面引入ExtJs需要 ...

  8. js分析 猫_眼_电_影 字体文件 @font-face

    0. 参考 https://developer.mozilla.org/zh-CN/docs/Web/CSS/@font-face 这是一个叫做@font-face 的CSS @规则 ,它允许网页开发 ...

  9. python之基于libsvm识别数字验证码

    1. 参考 字符型图片验证码识别完整过程及Python实现 2.图片预处理和手动分类 (1)分析图片 from PIL import Image img = Image.open('nums/ttt. ...

  10. [转]sourcetree 安装-Windows

    https://blog.csdn.net/weialemon/article/details/78833419 sourcetree官网地址:https://www.sourcetreeapp.co ...