poj2116 模拟题
不知道错在哪里
- /*
- 给定两个斐波那契表示数,要求用标准化表达方式表达
- 然后将这两个数加起来,和也用标准化方式表达
- 思路:显然要将这两个数先用十进制表示,和也用十进制表示
- 然后在转化成二进制即可
- 1 1 2 3 5 8 13 21 34
- 用贪心法能保证1不连续
- */
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #define ll long long
- using namespace std;
- ll f[],a,b,c;
- char buf[],s1[],s2[];
- void init(){
- f[]=;f[]=;
- for(int i=;i<=;i++)
- f[i]=f[i-]+f[i-];
- }
- int ans1[],ans2[],ans3[],len1,len2,len3;
- void solve(ll a,int *ans){//把a分解成斐波那契数列
- for(int i=;i>=;i--){
- if(a==) ans[-i]=;
- else if(a>=f[i]){
- ans[-i]=;
- a-=f[i];
- }
- else ans[-i]=;
- }
- }
- int main(){
- init();
- while(scanf("%s %s",s1,s2)==){
- memset(ans1,,sizeof ans1);
- memset(ans2,,sizeof ans2);
- memset(ans3,,sizeof ans3);
- a=b=c=;
- int Len1=strlen(s1);
- int Len2=strlen(s2);
- for(int i=;i<Len1;i++)
- a+=(s1[i]-'')*f[Len1-i];
- for(int i=;i<Len2;i++)
- b+=(s2[i]-'')*f[Len2-i];
- c=a+b;
- solve(a,ans1);
- solve(b,ans2);
- solve(c,ans3);
- /*for(int i=0;i<=39;i++)cout<<ans1[i];
- puts("");
- for(int i=0;i<=39;i++)cout<<ans2[i];
- puts("");
- for(int i=0;i<=39;i++)cout<<ans3[i];
- puts("");*/
- len1=len2=len3=;
- while(ans1[len1]==)
- len1++;
- while(ans2[len2]==)
- len2++;
- while(ans3[len3]==)
- len3++;
- printf(" ");
- for(int i=len3;i<len1;i++)
- printf(" ");
- for(int i=len1;i<=;i++)
- printf("%d",ans1[i]);
- puts("");
- printf("+ ");
- for(int i=len3;i<len2;i++)
- printf(" ");
- for(int i=len2;i<=;i++)
- printf("%d",ans2[i]);
- puts("");
- printf(" ");
- for(int i=len3;i<=;i++)
- printf("-");
- puts("");
- printf(" ");
- for(int i=len3;i<=;i++)
- printf("%d",ans3[i]);
- puts("");
- puts("");
- }
- return ;
- }
poj2116 模拟题的更多相关文章
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中
题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...
- UVALive 4222 Dance 模拟题
Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...
- cdoj 25 点球大战(penalty) 模拟题
点球大战(penalty) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- URAL 2046 A - The First Day at School 模拟题
A - The First Day at SchoolTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
随机推荐
- es教程
概念 关系数据库 ⇒ 数据库 ⇒ 表 ⇒ 行 ⇒ 列(Columns) Elasticsearch ⇒ 索引(Index) ⇒ 类型(type) ⇒ 文档(Docments) ⇒ 字段(Fields) ...
- mongodb系列~mongodb定时删除数据
一 简介:本文介绍创建自动删除数据的TTL索引 二 目的 定时删除数据三 创建方法 db.collection.createIndex(keys, options) options: ex ...
- Shell-find . -type f -name "*.log" -print0 | xargs -0 rm -f
用 rm 删除太多的文件时候,可能得到一个错误信息:/bin/rm Argument list too long.
- HAProxy详解(二):HAProxy基础配置与应用实例
一.HAProxy基础配置与应用实例: 1.快速安装HAProxy集群软件: HAProxy的官网: https://www.haproxy.org/#down下载HAProxy的源码包. 安装: [ ...
- python字典不区分大小写
from multidict import CIMultiDict dic=CIMultiDict() dic["key"]="1234" print(dic[ ...
- C++类的继承中构造函数和析构函数调用顺序例子
/*当建立一个对象时,首先调用基类的构造函数,然后调用下一个派生类的构造函数,依次类推,直至到达派生类次数最多的派生次数最多的类的构造函数为止.简而言之,对象是由“底层向上”开始构造的.因为,构造函数 ...
- VS2017中VC++项目添加StringTable资源
1.在资源视图中选择Resource.rc,右键弹出菜单,选择[添加资源] 2.在[添加菜单]对话框中选择[String Table],新建即可
- 修改JDK版本配置
我使用的maven是3.0.5版本的,在创建项目的时候,默认使用的jdk为1.5版本 在项目的pom.xml中添加如下配置可修改使用的jdk版本. <properties> <!-- ...
- HBase在HDFS上的目录介绍
总所周知,HBase 是天生就是架设在 HDFS 上,在这个分布式文件系统中,HBase 是怎么去构建自己的目录树的呢? 第一,介绍系统级别的目录树. 一.0.94-cdh4.2.1版本 系统级别的一 ...
- web网页测试用例(非常实用)
转自:http://blog.csdn.net/yuki_ying/article/details/54946541 一.Web测试中,各类web控件测试点总结 一 .界面检查 进入一个页面测试,首先 ...