Death to Binary? 分析模拟
/**
题目:Death to Binary?
链接:https://vjudge.net/contest/154246#problem/T
题意:略。
思路:
注意事项:
给的字符串存在前导0;
存在0+0 */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+;
const double eps = 1e-;
ll f[];
int la, lb, lc;
void init()
{
f[] = ;
f[] = ;
for(int i = ; i < ; i++){
f[i] = f[i-]+f[i-];
}
} void removeLeadZero(char a[])
{
int len = strlen(a);
int i = ;
while(i<len&&a[i]==''){
i++;
}
if(i==len){
a[] = '';
a[] = '\0';
}else
strcpy(a,a+i);
}
void canonical(char a[])
{
int len = strlen(a);
int flag = ;
char temp[];
int t = ;
temp[t++] = a[];
for(int i = ; i < len; i++){
if(a[i]==a[i-]&&a[i]==''){
flag = ;
if(t!=){
temp[t-] = '';
t--;
}
temp[t++] = '';
temp[t++] = '';
i++;
while(i<len){
temp[t++] = a[i++];
}
break;
}else
{
temp[t++] = a[i];
}
}
temp[t] = '\0';
if(flag) canonical(temp);
strcpy(a,temp);
}
void getC(ll x,char c[])
{
lc = ;
int pos;
for(int i = ; i < ; i++){
if(f[i]>x){
pos = i;
break;
}
}
pos = pos-;
while(pos>=){
if(f[pos]<=x){
c[lc++] = '';
x -= f[pos];
}else
{
c[lc++] = '';
}
pos--;
}
if(lc==){
c[lc++] = '';
}
c[lc] = '\0';
}
void print(char a[],char b[],char c[])
{
canonical(a);
canonical(b);
canonical(c);
//printf("a = %s b = %s c = %s\n",a,b,c);
lc = strlen(c);
la = strlen(a);
lb = strlen(b);
int sp = +lc-la;
while(sp--){
printf(" ");
}
printf("%s\n",a);
printf("+");
sp = +lc-lb-;
while(sp--){
printf(" ");
}
printf("%s\n",b);
printf(" ");
sp = lc;
while(sp--){
printf("-");
}
printf("\n");
printf(" ");
printf("%s\n\n",c);
}
int main()
{
char a[], b[], c[];
init();
while(scanf("%s%s",a,b)==)
{
removeLeadZero(a);
removeLeadZero(b);
//printf("a = %s\n",a);
//printf("b = %s\n",b);
ll sa, sb, sc;
sa = sb = ;
la = strlen(a);
lb = strlen(b);
for(int i = la-; i >= ; i--){
if(a[i]==''){
sa += f[la--i];
}
}
for(int i = lb-; i >= ; i--){
if(b[i]==''){
sb += f[lb--i];
}
} sc = sa+sb;
getC(sc,c);
//printf("a = %s\n",a);
//printf("c = %s\n",c);
//printf("sa = %lld sb = %lld\n",sa,sb);
print(a,b,c);
}
return ;
}
Death to Binary? 分析模拟的更多相关文章
- Death to Binary? (模拟)题解
思路: 除去前导0,注意两个1不能相邻(11->100),注意 0 *** 或者*** 0或者0 0情况 用string的reverse()很舒服 代码: #include<cstdio& ...
- poj 2116 Death to Binary? 模拟
Death to Binary? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1707 Accepted: 529 D ...
- 【教程】手把手教你如何利用工具(IE9的F12)去分析模拟登陆网站(百度首页)的内部逻辑过程
[前提] 想要实现使用某种语言,比如Python,C#等,去实现模拟登陆网站的话,首先要做的事情就是使用某种工具,去分析本身使用浏览器去登陆网页的时候,其内部的执行过程,内部逻辑. 此登陆的逻辑过程, ...
- 2017 Wuhan University Programming Contest (Online Round) C. Divide by Six 分析+模拟
/** 题目:C. Divide by Six 链接:https://oj.ejq.me/problem/24 题意:给定一个数,这个数位数达到1e5,可能存在前导0.问为了使这个数是6的倍数,且没有 ...
- POJ2116 Death to Binary?
/* POJ2116 Death to Binary? http://poj.org/problem?id=2116 齐肯多夫定理 */ #include <cstdio> #includ ...
- SBX(Simulated binary crossover)模拟二进制交叉算子和DE(differential evolution)差分进化算子
一起来学演化计算-SBX(Simulated binary crossover)模拟二进制交叉算子和DE(differential evolution)差分进化算子 觉得有用的话,欢迎一起讨论相互学习 ...
- 从session实现机制分析模拟请求验证码的可行性(转)
悲剧了,发现写完这篇blog没有配上这个格调超高的标题. 1.0问题背景 现在要实现一个带验证码网站的的自动登陆功能.验证码识别过程不再这篇文章的讨论之中.(之后有篇文章我会详细的总结验证码的识别 ...
- Codeforces 916B Jamie and Binary Sequence ( 模拟 && 思维 )
题意 : 给出一个数 n ,要求你用 k 个二的幂来组成这个数,要求输出这 k 个二的幂的指数,如果有多解情况则优先输出最大指数最小的那一个且要求按字典序输出,不存在则输出 No 分析 : 先来说一 ...
- fzu 2250 不可能弹幕结界 分析+模拟,考察思维严谨。
Problem 2250 不可能弹幕结界 Accept: 5 Submit: 13Time Limit: 1000 mSec Memory Limit : 65536 KB Problem ...
随机推荐
- Layui 使用问题汇总
1. Layui数据表格中checkbox位置不居中 使用方法渲染的方式生成数据表格,添加了checkbox,但发现checkbox位置不居中,如下图所示 解决办法 通过layui官方社区,找到如下代 ...
- 【FTP】java FTPClient 文件上传内容为空,文件大小为0
问题:如题所述,使用FTPClient上传至FTP服务器, 表现如下:①文件大小为0 ②上传很小的文件,但是要花费很长的时间,20K要花费2分钟甚至更久 ③没有任何的报错,没有任何的乱码 解决方法: ...
- Array.apply 方法的使用
Array.apply(null, {length: 5}) length为特殊字段,意思是生成一个长度为5的数组,由于没赋值,所以都是undefined; 如果要赋值,可以这样 console.lo ...
- PostgreSQL配置文件--资源使用(除WAL外)
2 资源使用(除WAL外) RESOURCE USAGE (except for WAL) 2.1 内存 Memory 2.1.1 shared_buffers 数字型 默认: shared_buff ...
- Server 2008 R2 安装活动目录和配置DNS及故障解决
一.安装windows2008_64bit_r2 给服务器设置密码:xxxxxxxx 二.安装配置DNS规则 1.更改服务器主机名:DCserver 2.配置静态IP地址 IP地址:10.0.100. ...
- 处理 WebService 中的 Map 对象
最近,我们讨论了关于 WebService 的相关问题.目前在 Smart 中,可发布两种类型的 WebService,它们是:SOAP 服务 与 REST 服务,您可以根据需要自由选择. 今天,我要 ...
- netty4 ServerBootstrap.bind(port) debug
代码是netty4自带的例子 我们在bind的行前加个断电,下面是ServerBootstrap.bind(port)方法所经历的一些步骤. 在AbstractBootstrap.initAndReg ...
- docker实战——Docker本地私有镜像仓库Harbor搭建及配置
Harbor介绍 Docker容器应用的开发和运行离不开可靠的镜像管理,虽然docker官方提供了公共的镜像仓库(Docker Hub),但是从安全和效率等方面考虑,部署我们私有环境内的Registr ...
- Java并发包——Blockingqueue,ConcurrentLinkedQueue,Executors
背景 通过做以下一个小的接口系统gate,了解一下mina和java并发包里的东西.A系统为javaweb项目,B为C语言项目,gate是本篇须要完毕的系统. 需求 1. A为集群系统,并发较高,会批 ...
- IEEE会议投稿资料汇总http://cadcg2015.nwpu.edu.cn/index.htm
近期投了篇IEEE的顶级会议文章,一下是比較实用的一些资料,以供參考. 1.会议主页:http://cadcg2015.nwpu.edu.cn/index.htm (The 14th Inte ...