构造。

(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. [LeetCode] 12. Integer to Roman ☆☆

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  2. 使用localhost调试本地代码,setcookie无效

    今天在本地调试代码的时候,再域名中使用localhost,结果一直调试不成功,最后发现在登录时,setcookie()没有设置进去 于是发现了,在使用localhost调试时,保存cookie是无效的 ...

  3. mysql 服务端事务和客户端事务对比分析

    之前做mysql事务测试的时候都是在mysql服务端存储过程里面包含事务. 例如: CREATE DEFINER=`root`@`localhost` PROCEDURE `Test`(out deb ...

  4. 【洛谷 P1707】 刷题比赛 (矩阵加速)

    题目连接 很久没写矩阵加速了,复习一下,没想到是一道小毒瘤题. 状态矩阵\(a[k],b[k],c[k],a[k+1],b[k+1],c[k+1],k,k^2,w^k,z^k,1\) 转移矩阵 0, ...

  5. Super A^B mod C (快速幂+欧拉函数+欧拉定理)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 题目:Problem Description Given A,B,C, You should quick ...

  6. Webview 中FaultyInfo代码说明

    class FaultyInfoHandler(tornado.web.RequestHandler): def get(self): import xmlrpc.client s = xmlrpc. ...

  7. hdu 2680 Choose the best route (dijkstra算法 最短路问题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Time Limit: 2000/1000 MS ( ...

  8. 工程化管理--maven

    mavne模型 可以看出 maven构件都是由插件支撑的 maven的插件位置在:F:\MavenRepository\org\apache\maven\plugins Maven仓库布局 本地仓库 ...

  9. promise 如何知道所有的回调都执行完了?

    var fs = require('fs'); /** * @return {object} Promise */ function doThing(fileName) { // ... // con ...

  10. socket.io入门整理

    我自己在用socket.io开发,对官方网站上的文档,进行简单的整理,然后自己写了一个简单的聊天程序. 最最开始 先安装socket.io: 1 npm install socket.io 利用Nod ...