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 ...
随机推荐
- Lucene6.6添加索引数据时字符个数超限,字符数不能超过BYTE_BLOCK_SIZE=32766
最近发现Lucene6.6版本添加索引数据字符数超过32766时,出现报错,而Lucene4.6版本中则未出现这一问题,原因如下: 概述: 添加索引数据时,对于分词字段,分词后的Ter ...
- linux shell读取配置文件
配置文件CoverageInfo FTP_URL=ftp://svn-fb.sicent.com:21/jenkins/Jifei_Repo/OL-2/IDC_Platform/bar_seats_c ...
- rdlc 格式设置
在用vs2013开发rdlc报表时,发现好多报表样式问题: 1.导出的pdf偶数页总是空白页. 2.导出的Excel打印时,内容显示不全. 3.word内容显示不全. 查了好多资料终于找到解决方案了, ...
- javascript继承机制 & call apply使用说明
一.继承机制 1.对象冒充:构造函数使用 this 关键字给所有属性和方法赋值,可使 ClassA 构造函数成为 ClassB 的方法,然后调用它. function ClassZ() { this. ...
- Python模块学习 - openpyxl
openpyxl模块介绍 openpyxl模块是一个读写Excel 2010文档的Python库,如果要处理更早格式的Excel文档,需要用到额外的库,openpyxl是一个比较综合的工具,能够同时读 ...
- Python模块学习 - Functools
Functools模块 Higher-order functions and operations on callable objects,看这个标题我都是懵逼的,这都是啥啥啥啊,赶紧拿出百度翻译:可 ...
- Caffe 学习笔记1
Caffe 学习笔记1 本文为原创作品,未经本人同意,禁止转载,禁止用于商业用途!本人对博客使用拥有最终解释权 欢迎关注我的博客:http://blog.csdn.net/hit2015spring和 ...
- python基础===列表类型的所有方法
链表类型有很多方法,这里是链表类型的所有方法: append(x) 把一个元素添加到链表的结尾,相当于a[len(a):] = [x] extend(L) 通过添加指定链表的所有元素来扩充链表,相当于 ...
- iframe的一些介绍
iframe 元素会创建包含另外一个文档的内联框架(即行内框架) 提示:您可以把需要的文本放置在 <iframe> 和 </iframe> 之间,这样就可以应对无法理解 ifr ...
- linux命令(34):less命令
1.命令格式: less [参数] 文件 2.命令功能: less 与 more 类似,但使用 less 可以随意浏览文件,而 more 仅能向前移动,却不能向后移动,而且 less 在查看之前不会 ...