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

用大数处理出100项fib。然后模拟交替置位位0或者1,输出

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
const int numlen=;
struct bign {
int len, s[numlen];
bign() {
memset(s, , sizeof(s));
len = ;
}
bign(int num) { *this = num; }
bign(const char *num) { *this = num; }
bign operator = (const int num) {
char s[numlen];
sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator = (const char *num) {
len = strlen(num);
while(len > && num[] == '') num++, len--;
for(int i = ;i < len; i++) s[i] = num[len-i-] - '';
return *this;
} void deal() {
while(len > && !s[len-]) len--;
} bign operator + (const bign &a) const {
bign ret;
ret.len = ;
int top = max(len, a.len) , add = ;
for(int i = ;add || i < top; i++) {
int now = add;
if(i < len) now += s[i];
if(i < a.len) now += a.s[i];
ret.s[ret.len++] = now%;
add = now/;
}
return ret;
}
bign operator - (const bign &a) const {
bign ret;
ret.len = ;
int cal = ;
for(int i = ;i < len; i++) {
int now = s[i] - cal;
if(i < a.len) now -= a.s[i];
if(now >= ) cal = ;
else {
cal = ; now += ;
}
ret.s[ret.len++] = now;
}
ret.deal();
return ret;
}
bign operator * (const bign &a) const {
bign ret;
ret.len = len + a.len;
for(int i = ;i < len; i++) {
for(int j = ;j < a.len; j++)
ret.s[i+j] += s[i]*a.s[j];
}
for(int i = ;i < ret.len; i++) {
ret.s[i+] += ret.s[i]/;
ret.s[i] %= ;
}
ret.deal();
return ret;
} bign operator * (const int num) {
// printf("num = %d\n", num);
bign ret;
ret.len = ;
int bb = ;
for(int i = ;i < len; i++) {
int now = bb + s[i]*num;
ret.s[ret.len++] = now%;
bb = now/;
}
while(bb) {
ret.s[ret.len++] = bb % ;
bb /= ;
}
ret.deal();
return ret;
} bign operator / (const bign &a) const {
bign ret, cur = ;
ret.len = len;
for(int i = len-;i >= ; i--) {
cur = cur*;
cur.s[] = s[i];
while(cur >= a) {
cur -= a;
ret.s[i]++;
}
}
ret.deal();
return ret;
} bign operator % (const bign &a) const {
bign b = *this / a;
return *this - b*a;
} bign operator += (const bign &a) { *this = *this + a; return *this; }
bign operator -= (const bign &a) { *this = *this - a; return *this; }
bign operator *= (const bign &a) { *this = *this * a; return *this; }
bign operator /= (const bign &a) { *this = *this / a; return *this; }
bign operator %= (const bign &a) { *this = *this % a; return *this; } bool operator < (const bign &a) const {
if(len != a.len) return len < a.len;
for(int i = len-;i >= ; i--) if(s[i] != a.s[i])
return s[i] < a.s[i];
return false;
}
bool operator > (const bign &a) const { return a < *this; }
bool operator <= (const bign &a) const { return !(*this > a); }
bool operator >= (const bign &a) const { return !(*this < a); }
bool operator == (const bign &a) const { return !(*this > a || *this < a); }
bool operator != (const bign &a) const { return *this > a || *this < a; } string str() const {
string ret = "";
for(int i = ;i < len; i++) ret = char(s[i] + '') + ret;
return ret;
}
};
istream& operator >> (istream &in, bign &x) {
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator << (ostream &out, const bign &x) {
out << x.str();
return out;
}
char a[numlen],b[numlen];
bign fib[numlen];
void init()
{
fib[]=;fib[]=; fib[]=;
for (int i=;i<numlen;i++) fib[i]=fib[i-]+fib[i-];
}
bign trans(char *a)
{
bign sum=;
int len=strlen(a);
for (int i=;i<=len;i++)
if (a[i-]=='')
sum+=fib[len-i+];
//cout<<sum<<endl;
return sum;
}
bign tmp;
void slove(bign sum)
{
if (sum==tmp) {puts("");return ;}
int i=;
for (i=;i<numlen;i++)
if (fib[i]>sum) break;
i--;
bool flag=true;
for (;i>;i--)
{
//cout<<sum<<' '<<fib[i]<<endl;
if (fib[i]<=sum && flag)
{
printf("");
sum=sum-fib[i];
flag=false;
}
else
{
printf("");
flag=true;
}
}
putchar('\n');
}
int main()
{
init();
bool first=false;
while (scanf("%s%s",a,b)!=EOF)
{
if (first) putchar('\n');
else first=true;
tmp=;
bign num1=trans(a);
bign num2=trans(b);
bign sum=num1+num2;
//cout<<sum<<endl;
//for (int i=1;i<=10;i++) cout<<fib[i]<<' ';cout<<endl;
slove(sum);
}
return ;
}

UVA 763 Fibinary Numbers的更多相关文章

  1. UVa 10006 - Carmichael Numbers

    UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some ...

  2. Uva - 12050 Palindrome Numbers【数论】

    题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然 ...

  3. UVA.136 Ugly Numbers (优先队列)

    UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,5倍均是丑数,且 ...

  4. UVA - 13022 Sheldon Numbers(位运算)

    UVA - 13022 Sheldon Numbers 二进制形式满足ABA,ABAB数的个数(A为一定长度的1,B为一定长度的0). 其实就是寻找在二进制中满足所有的1串具有相同的长度,所有的0串也 ...

  5. UVA - 136 Ugly Numbers (有关set使用的一道题)

    Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, ...

  6. POJ2402/UVA 12050 Palindrome Numbers 数学思维

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...

  7. UVA 10006 - Carmichael Numbers 数论(快速幂取模 + 筛法求素数)

      Carmichael Numbers  An important topic nowadays in computer science is cryptography. Some people e ...

  8. UVa 11461 - Square Numbers【数学,暴力】

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  9. UVA 350 Pseudo-Random Numbers

     Pseudo-Random Numbers  Computers normally cannot generate really random numbers, but frequently are ...

随机推荐

  1. 进入saftmode解决方案

    Name node is in safe mode.The reported blocks 356 needs additional 2 blocks to reach the threshold 0 ...

  2. notepad++ 换行技巧 log换行

    有时候,服务器收集上来的日志,格式很乱,看log很难,如下: java.lang.IllegalStateException: BEvent.init() must be call first\n\t ...

  3. 开启虚拟机所报的错误:VMware Workstation cannot connect to the virtual machine. Make sure you have rights to run the program, access all directories the program uses, and access all directories for temporary fil

    当我们开启虚拟机时出现错误: VMware Workstation cannot connect to the virtual machine. Make sure you have rights t ...

  4. VSX-4 VSXTra

    要介绍VSXTra项目不是一个简单的事情. 而且要在上面进行扩展,删减就更不容易. 源码分析的资料几乎没有,可怜的几个示例项目,相较而言,英文已经不是阻碍我前进的步伐了. 本篇只是简单的分析,对于已经 ...

  5. lnmp一键安装环境中nginx开启pathinfo

    问题及原理可参考:http://www.laruence.com/2009/11/13/1138.html 如果是用lnmp脚本一键安装的开发环境,可以通过如下方式开户pathinfo: 1.注释ng ...

  6. Python 实现随机打乱字符串

    from random import shuffle def shuffle_str(s): # 将字符串转换成列表 str_list = list(s) # 调用random模块的shuffle函数 ...

  7. Canvas 图片平铺设置

    /** * 图片平铺 */ function initDemo7(){ var canvas = document.getElementById("demo7"); if (!ca ...

  8. Android之SeekBar总结(一)

    2015-04-24 SeekBar: 一种特殊的进度条,包含一个滑块用于调节进度值. API 中目录结构如下: 包含几种特殊的属性: 1: max:设置进度条的最大值 .对应方法:setMax(in ...

  9. JavaScript里面之dom操作

    1.dom之选择元素 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  10. NYOJ36 水池数目

    水池数目 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 南阳理工学院校园里有一些小河和一些湖泊,现在,我们把它们通一看成水池,假设有一张我们学校的某处的地图,这个地 ...