ZOJ 3327 Friend Number
构造。
(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的更多相关文章
- ZOJ 3622 Magic Number 打表找规律
A - Magic Number Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Subm ...
- ZOJ 3436 July Number(DFS)
题意 把一个数替换为这个数相邻数字差组成的数 知道这个数仅仅剩一位数 若最后的一位数是7 则称原来的数为 July Number 给你一个区间 求这个区间中July Number的个数 ...
- ZOJ 3233 Lucky Number
Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...
- [ZOJ 3622] Magic Number
Magic Number Time Limit: 2 Seconds Memory Limit: 32768 KB A positive number y is called magic n ...
- ZOJ 3622 Magic Number(数)
题意 假设一个正整数y满足 将随意正整数x放到y的左边得到的数z满足 z%y==0 那么这个数就是个Magic Number 给你一个范围 求这个范围内Magic Number的个数 令 ...
- zoj 1526 Big Number 数学
Big Number Time Limit: 10 Seconds Memory Limit: 32768 KB In many applications very large intege ...
- ZOJ 3886 Nico Number(筛素数+Love(线)Live(段)树)
problemCode=3886">ZOJ 3886 题意: 定义一种NicoNico数x,x有下面特征: 全部不大于x且与x互质的数成等差数列,如x = 5 ,与5互素且不大于5的数 ...
- ZOJ 3690 Choosing number(矩阵)
Choosing number [题目链接]Choosing number [题目类型]矩阵 &题解: 这题就和已经dp极像了,所以找方程就很困难了.可以这样找: 设f(n)是前n-1个人已经 ...
- 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 ...
随机推荐
- [ASP.NET]从ASP.NET Postback机制,到POST/GET方法
写这篇博客的起源来自于自己最近在学习ASP.NET时对于 PostBack机制的困惑.因为自己在解决困惑地同时,会不断产生新的疑问,因此博客最后深入到了http 包的格式和Internet所使用的TC ...
- 51Nod 1305 Pairwise Sum and Divide | 思维 数学
Output 输出fun(A)的计算结果. Input示例 3 1 4 1 Output示例 4 first try: #include "bits/stdc++.h" using ...
- kafka命令总结
./kafka-console-consumer.sh --bootstrap-server IP:9092 --topic user-asset-change-v1 --partition 2 ...
- 逃生(HDU4857 + 反向拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4857 题面是中文题面,就不解释题意了,自己点击链接去看下啦~这题排序有两个条件,一个是按给定的那个序列 ...
- js_跑马灯
跑马灯?刚听到这个词的时候,脑袋第一个想到的是跑马?嗯?就是香港的那种跑马场.懂?其次就是霓虹灯了,一闪一闪的多好看. 霓虹灯?哦,那是城市的杰作,记忆中是.开往城市边缘开,把车窗都摇下来,用速度换一 ...
- Java多线程学习(二)synchronized关键字(1)
转载请备注地址: https://blog.csdn.net/qq_34337272/article/details/79655194 Java多线程学习(二)将分为两篇文章介绍synchronize ...
- 【转】ps命令详解
原文地址:http://apps.hi.baidu.com/share/detail/32573968 有 时候系统管理员可能只关心现在系统中运行着哪些程序,而不想知道有哪些进程在运行.由于一个应用程 ...
- linux下实现在程序运行时的函数替换(热补丁)【转】
转自:http://www.cnblogs.com/leo0000/p/5632642.html 声明:以下的代码成果,是参考了网上的injso技术,在本文的最后会给出地址,同时非常感谢injso技术 ...
- 安全测试===sqlmap
本文转自:https://www.secpulse.com/archives/4213.html 鉴于很多新手对sqlmap的用法不是很熟悉 很多常用sqlmap的也不一定完全会用sqlmap 特 ...
- python基础===字符串的制表,换行基础操作
\n\t 制表符和换行符 >>> print("Languages:\n\tPython\n\tC\n\tJavaScript") Languages: Pyth ...