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 ...
随机推荐
- 洛谷 3029 [USACO11NOV]牛的阵容Cow Lineup
https://www.luogu.org/problem/show?pid=3029 题目描述 Farmer John has hired a professional photographer t ...
- 2015/8/9 到家了,学完了CodeCademy的Python
昨天坐了20多个小时的硬座回家.发现在网络信号差的火车上也是学习的好地方.如果你的手机电量不足的话,带上两本书简直是绝配.我在火车上阅读了两百多页的内容,并没有多大的疲累,那样无聊的环境里面能看书学习 ...
- [Luogu 2604] ZJOI2010 网络扩容
[Luogu 2604] ZJOI2010 网络扩容 第一问直接最大流. 第二问,添加一遍带费用的边,边权 INF,超级源点连源点一条容量为 \(k\) 的边来限流,跑费用流. 大约是第一次用 nam ...
- 【BZOJ】1954: Pku3764 The xor-longest Path
[算法]trie树+xor路径 [题解] 套路1:统计从根到每个点的xor路径和,由于xor的自反性,两个点到根的xor路径和异或起来就得到两点间路径和. 然后问题就是找到n个值中异或值最大的两个值, ...
- el-date-picker 日期格式化 yyyy-MM-dd
<el-date-picker format="yyyy-MM-dd" v-model="dateValue" type="date" ...
- 变量对象vs活动对象
这是我见过描述的最为详尽的关于变量对象.活动对象以及闭包的解析,来自知乎,感谢答主: 作者:闭家锁链接:https://www.zhihu.com/question/36393048/answer/7 ...
- gpio子系统和pinctrl子系统(下)
情景分析 打算从两个角度来情景分析,先从bsp驱动工程师的角度,然后是驱动工程师的角度,下面以三星s3c6410 Pinctrl-samsung.c为例看看pinctrl输入参数的初始化过程(最开始的 ...
- FAN54015 充電電流 軟硬體設定
Ex1: Vrsense 選 37.4 mV --- 在第二張圖 Rsense 選 50 mΩ --- 在第三張圖 37.4 / 50 = 748 mA Ex2: Vrsense 選 44.2 mV ...
- docker配置桥接网络
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# cp ifcfg-et ...
- Python构造函数使用
1. 子类不定义构造函数时候,默认引用父类构造函数 class A(object): def __init__(self,name): self.name = name def run(self): ...