构造。

(1)如果数字中带有$0$:

1.只有个位是$0$,这种情况就是给输入的数字$+10$再输出即可。

2.其余情况就是给输入的数字$+1$再输出即可。

(2)如果数字中没有$0$:

从个位开始一位一位拆掉。如果发现能凑出比某一位大一点点的数字,那么剩下的高位就不动了,再从个位开始构造目前能凑出的最大数字。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} char s[];
int T,c[],len; void F(int x,int f)
{
if(x==) return ;
else if(x==) c[]=c[]+f*;
else if(x==) c[]=c[]+f*;
else if(x==) c[]=c[]+f*;
else if(x==) c[]=c[]+f*;
else if(x==) c[]=c[]+f*, c[]=c[]+f*;
else if(x==) c[]=c[]+f*;
else if(x==) c[]=c[]+f*;
else if(x==) c[]=c[]+f*;
} int G(int x)
{
if(x==-)
{
if(c[]>=||c[]>=) return ;
if(c[]>=||c[]>=) return ;
if(c[]>=) return ;
if(c[]>=||(c[]>=&&c[]>=)) return ;
if(c[]>=) return ;
if(c[]>=||c[]>=) return ;
if(c[]>=) return ;
if(c[]>=) return ;
return ;
} else
{
if(x<&&(c[]>=)) return ;
if(x<&&(c[]>=)) return ;
if(x<&&(c[]>=||c[]>=)) return ;
if(x<&&(c[]>=)) return ;
if(x<&&(c[]>=||(c[]>=&&c[]>=))) return ;
if(x<&&(c[]>=)) return ;
if(x<&&(c[]>=||c[]>=)) return ;
if(x<&&(c[]>=||c[]>=)) return ;
}
} int main()
{
scanf("%d",&T);
while(T--)
{
memset(s,,sizeof s); memset(c,,sizeof c); scanf("%s",s); len=strlen(s);
for(int i=;i<len/;i++) swap(s[i],s[len-i-]); int sum=;
for(int i=;i<len;i++) if(s[i]=='') sum++; if(sum==)
{
bool flag=;
for(int i=;i<len;i++)
{
F(s[i]-'',);
if(G(-)>s[i]-'')
{
flag=;
int num1=G(s[i]-'');
s[i]=num1+'';
F(num1,-);
for(int j=;j<i;j++)
{
int num=G(-);
if(num==) break;
s[j]=num+'';
F(num,-);
}
break;
}
else s[i]='';
} if(flag==)
{
s[len]=''; len++;
for(int i=;i<len;i++)
{
int num=G(-);
if(num==) break;
s[i]=num+'';
F(num,-);
}
}
} else
{
int pos;
if(sum==&&s[]=='') pos=;
else pos=; int k=;
for(int i=pos;i<len;i++)
{
int tmp=s[i]-'';
s[i]=((tmp+k)%)+'';
k=(tmp+k)/;
}
if(k!=) s[len]=k+'', len++;
} for(int i=len-;i>=;i--) printf("%c",s[i]);
printf("\n");
}
return ;
}

ZOJ 3327 Friend Number的更多相关文章

  1. ZOJ 3622 Magic Number 打表找规律

    A - Magic Number Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Subm ...

  2. ZOJ 3436 July Number(DFS)

    题意   把一个数替换为这个数相邻数字差组成的数  知道这个数仅仅剩一位数  若最后的一位数是7  则称原来的数为 July Number  给你一个区间  求这个区间中July Number的个数 ...

  3. ZOJ 3233 Lucky Number

    Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...

  4. [ZOJ 3622] Magic Number

    Magic Number Time Limit: 2 Seconds      Memory Limit: 32768 KB A positive number y is called magic n ...

  5. ZOJ 3622 Magic Number(数)

    题意  假设一个正整数y满足  将随意正整数x放到y的左边得到的数z满足 z%y==0  那么这个数就是个Magic Number   给你一个范围  求这个范围内Magic Number的个数 令 ...

  6. zoj 1526 Big Number 数学

    Big Number Time Limit: 10 Seconds      Memory Limit: 32768 KB In many applications very large intege ...

  7. ZOJ 3886 Nico Number(筛素数+Love(线)Live(段)树)

    problemCode=3886">ZOJ 3886 题意: 定义一种NicoNico数x,x有下面特征: 全部不大于x且与x互质的数成等差数列,如x = 5 ,与5互素且不大于5的数 ...

  8. ZOJ 3690 Choosing number(矩阵)

    Choosing number [题目链接]Choosing number [题目类型]矩阵 &题解: 这题就和已经dp极像了,所以找方程就很困难了.可以这样找: 设f(n)是前n-1个人已经 ...

  9. ZOJ 3702 Gibonacci number 2017-04-06 23:28 28人阅读 评论(0) 收藏

    Gibonacci number Time Limit: 2 Seconds      Memory Limit: 65536 KB In mathematical terms, the normal ...

随机推荐

  1. oracle 存储过程 技巧

    我们在进行pl/sql编程时打交道最多的就是存储过程了.存储过程的结构是非常的简单的,我们在这里除了学习存储过程的基本结构外,还会学习编写存储过程时相关的一些实用的知识.如:游标的处理,异常的处理,集 ...

  2. jquery 遮罩层显示img

    如果点击iframe中的image显示整个页面的遮罩层,可参考如下: http://blog.csdn.net/shiaijuan1/article/details/70160714 具体思路就是,顶 ...

  3. 【bzoj1593-预定旅馆】线段树维护连续区间

    题解: 这题非常经典啊似乎..经典模型要记住啊.. 对于每个节点维护该区间里的最大的连续区间,然后我们就可以logn递归找最前面的一段. 那就维护mx(无限制),lmx(必须从左边开始),rmx(必须 ...

  4. 12.24笔记(关于//UIDynamic演练//多对象的附加行为//UIDynamic简单演练//UIDynamic//(CoreText框架)NSAttributedString)

          12.24笔记1.UIDynamic注意点:演示代码:上面中设置视图旋转的时候,需要注意设置M_PI_4时,视图两边保持平衡状态,达不到仿真效果.需要偏移下角度.2.吸附行为3.推动行为初 ...

  5. vue清空input file

    input file是只读的,给form一个id,用form.reset()干掉里面input的值 document.getElementById("uploadForm")&am ...

  6. bzoj 1050 并查集

    先按边长排序,假设s与t连通,那么我们可以枚举s与t的路径中最短的一条边,通过类似与kruskal的方法找到s与t的路径在当前最小边权情况下尽量小的最大边权,用这个比值更新答案. 特别的,我们对于某一 ...

  7. Android控件——AutoCompleteTextView与MultiAutoCompleteTextView(实现自动匹配输入的内容)

    ------------------------------------AutoCompleteTextView----------------------

  8. Python学习笔记 - day12 - Python操作NoSQL

    NoSQL(非关系型数据库) NoSQL,指的是非关系型的数据库.NoSQL有时也称作Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统的统称.用于超大规模数据的存储.(例如 ...

  9. JS中的日期内置函数

    用JS中的日期内置函数实现在页面显示:“今天是:2013年9月26日14:32:45”. var date=new Date(Date.parse('9/26/2013 14:32:45'));   ...

  10. dump_stack 实现分析【转】

    转自:http://kernel.meizu.com/2017/03/18-40-19-dump_stack.html 1 简介 说起 dump_stack() ,相信从事 Linux 内核或者驱动相 ...