http://acm.hust.edu.cn/vjudge/contest/view.action?cid=30506#problem/V

题意:从右向左,每一个位数,分别表示一个fibonacci数,1表示有,0表示没有;求两个数的和,同样按照这种形式存储

#include<map>
#include<set>
#include<list>
#include<cmath>
#include<ctime>
#include<deque>
#include<stack>
#include<bitset>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<sstream>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional> using namespace std ;
const int maxn = 110 ;
char f1[ maxn + 10 ] , f2[ maxn + 10] , f[ maxn + 10 ] ; void Swap( char a[ ] )
{
int len = strlen( a ) ;
char temp ;
for( int i = 0 ; i < len / 2 ; ++ i )
{
temp = a[ i ] ;
a[ i ] = a[ len - i - 1 ] ;
a[ len - i - 1 ] = temp ;
}
} int main()
{
int Case = 0 ;
while( scanf( "%s%s" , f1 , f2 ) != EOF )
{
int len1 = strlen( f1 ) ;
int len2 = strlen( f2 ) ;
int len = len1 > len2 ? len1 : len2 ;
Swap( f1 ) ;
Swap( f2 ) ;
Case++ ;
if( Case != 1 )
{
printf( "\n" ) ;
}
memset( f , '0' , sizeof( f ) ) ;
for( int i = len1 ; i < maxn + 10 ; ++i )
{
f1[ i ] = '0' ;
}
for( int j = len2 ; j < maxn + 10; ++j )
{
f2[ j ] = '0' ;
}
for( int i = 0 ; i < len ; ++i )
{
f[ i ] = f1[ i ] + f2[ i ] - '0' ;
}
for( int i = 0 ; i < maxn ; ++i )
{
if( f[ i ] == '2' )
{
f[ i + 1 ] ++ ;
f[ i ] = '0' ;
if( i == 1 )
{
f[ i - 1 ]++ ;
i -= 2 ;
}
else if( i > 1 )
{
f[ i - 2 ]++ ;
i -= 3 ;
}
}
}
for( int i = maxn ; i >= 1 ; --i )
{
if( f[ i ] == '1' && f[ i - 1 ] == '1' )
{
f[ i ] = '0' ;
f[ i - 1 ] = '0' ;
f[ ++i ]++ ;
i += 2 ;
}
}
int i ;
for( i = maxn ; i >= 0 && f[ i ] == '0' ; --i );
{
if( i == -1 )
{
printf( "0" ) ;
}
else
{
for( ; i >= 0 ; -- i )
{
printf( "%c" , f[ i ] ) ;
} }
printf( "\n" ) ;
}
}
return 0;
}

Fibinary Numbers的更多相关文章

  1. UVA 763 Fibinary Numbers

    题意讲某个二进制按照规则每一位对应斐波那契数生成新的数字,然后2个数字求和.再求由该规则生成的二进制串.并且要求尽量用更大项的fib数(题目提示不能由连续的1就是2个连续的1(11)不如100更优) ...

  2. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  3. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  4. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  5. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  6. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  7. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

  8. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  9. [LeetCode] Valid Phone Numbers 验证电话号码

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

随机推荐

  1. 配置greenplum参数

    在进行一个greenplum安装之前需要进行配置一下相关的系统参数,否则很容易出现意想不到的错误. 1.修改系统参数 编辑 /etc/sysctl.conf ,以下是最小配置 kernel.shmma ...

  2. 机器学习笔记(一)- from Andrew Ng的教学视频

    最近算是一段空闲期,不想荒废,记得之前有收藏一个机器学习的链接Andrew Ng的网易公开课,其中的overfiting部分做组会报告时涉及到了,这几天有时间决定把这部课程学完,好歹算是有个粗浅的认识 ...

  3. ASP.NET MVC 以Stream 下载文件

     1.0以Stream 下载文件 nl.fileid = Int32.Parse(id); //服务器上对应的id Stream stream = Lawsuit.DownLoad(nl);//服务器 ...

  4. 在CentOS/RHEL/Scientific Linux 6下安装 LAMP

    LAMP 是服务器系统中开源软件的一个完美组合.它是 Linux .Apache HTTP 服务器.MySQL 数据库.PHP(或者 Perl.Python)的第一个字母的缩写代码.对于很多系统管理员 ...

  5. 错误处理try catch

    <?phpfunction inverse($x) { if (!$x) { throw new Exception('被除数不能为0'); } if ($x>31) { throw ne ...

  6. codeigniter ,看完这些,就可以用它做项目了

    一.MVC 1,入口文件 唯一一个让浏览器直接请求的脚本文件 2,控制器 controller 负责协调模型和视图 3,模型 model 只负责提供数据,保存数据 4,视图 只负责显示,以及搜集用户的 ...

  7. Codeforces 489A SwapSort

    这题第一次看的时候以为是区间替换,后来发现看错了,只是单纯的元素替换. 解题思路: 先对输入的序列加个数组排个序 遍历下来,如果和排序后的结果当前元素不同,设当前位置为 i, 则往下面找,设查找位置为 ...

  8. 开发板ip设置

    vi /etc/init.d/rcS 在其中加入 ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up 就可以了

  9. Mysql 连接查询 Mysql支持的连接查询有哪些

    CREATE TABLE `chx` (   `id` VARCHAR(20) NOT NULL,   `name` VARCHAR(50) DEFAULT NULL,   `name2` CHAR( ...

  10. Struct初学的,页面跳转

    Filter控制器 jsp页面代码 <form action="page_login.action" method="post">     user ...