hdu_1041(Computer Transformation) 大数加法模板+找规律
Computer Transformation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8367 Accepted Submission(s): 3139
How many pairs of consequitive zeroes will appear in the sequence after n steps?
3
1
规律:数串的右边一般是上一个数串,数串的左半边是上两个数串+上一个数串的左半区
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
const int N = ;
struct Node{
string sum;
string leftsum;
int left,right;//zuo ban qu
}node[N]; string add(string s1,string s2){ //大数 s1 + s2
if(s1.length()<s2.length()){
string temp=s1;
s1=s2;
s2=temp;
}
for(int i=s1.length()-,j=s2.length ()-;i>=;i--,j--){
s1[i]=char(s1[i]+( j>= ? s2[j]-'' : ));
if(s1[i]-''>=) {
s1[i]=char( (s1[i]-'')%+'' );
if(i) s1[i-]++;
else s1=""+s1;
}
}
return s1;
} void init()
{
/* for(int i = 0; i < N; i++){
node[i].sum ="0";
node[i].leftsum = "0";
}*/
node[].sum = "", node[].left = , node[].right = , node[].leftsum = "";
node[].sum = "", node[].left = , node[].right = , node[].leftsum = "";
for(int i = ; i < N; i++)
{
node[i].leftsum = add(node[i-].sum,node[i-].leftsum);
node[i].left = node[i-].left;
node[i].right = node[i-].right;
node[i].sum=add(node[i-].sum,node[i].leftsum);
if(node[i].right==node[i-].left&&node[i].right == ) node[i].sum = add(node[i].sum,"");
}
}
int main()
{
int n;
init();
while(~scanf("%d",&n)){
// printf("%s\n",node[n].sum);
cout<<node[n].sum<<endl;
}
return ;
}
大数加法模板
string add(string s1,string s2){ //大数 s1 + s2
if(s1.length()<s2.length()){
string temp=s1;
s1=s2;
s2=temp;
}
for(int i=s1.length()-,j=s2.length ()-;i>=;i--,j--){
s1[i]=char(s1[i]+( j>= ? s2[j]-'' : ));
if(s1[i]-''>=) {
s1[i]=char( (s1[i]-'')%+'' );
if(i) s1[i-]++;
else s1=""+s1;
}
}
return s1;
}
hdu_1041(Computer Transformation) 大数加法模板+找规律的更多相关文章
- vijos - P1447开关灯泡 (大数模板 + 找规律 + 全然数 + python)
P1447开关灯泡 Accepted 标签:CSC WorkGroup III[显示标签] 描写叙述 一个房间里有n盏灯泡.一開始都是熄着的,有1到n个时刻.每一个时刻i,我们会将i的倍数的灯泡改变状 ...
- HDU 1041 Computer Transformation(找规律加大数乘)
主要还是找规律,然后大数相乘 #include<stdio.h> #include<string.h> #include<math.h> #include<t ...
- HDOJ-1041 Computer Transformation(找规律+大数运算)
http://acm.hdu.edu.cn/showproblem.php?pid=1041 有一个初始只有一个1的串 每次都按①0 -> 10;②1 -> 01;这两条规则进行替换 形如 ...
- Computer Transformation(规律,大数打表)
Computer Transformation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- UVA - 1647 Computer Transformation(计算机变换)(找规律)
题意:初始串为一个1,每一步会将每个0改成10,每个1改成01,因此1会依次变成01,1001,01101001,……输入n(n<=1000),统计n步之后得到的串中,"00" ...
- HDU 1041 Computer Transformation (简单大数)
Computer Transformation http://acm.hdu.edu.cn/showproblem.php?pid=1041 Problem Description A sequenc ...
- hdu 5047 大数找规律
http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...
- Computer Transformation(简单数学题+大数)
H - Computer Transformation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &am ...
- hdu4952 Number Transformation (找规律)
2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...
随机推荐
- bzoj 2753: [SCOI2012]滑雪与时间胶囊
Description a180285非常喜欢滑雪.他来到一座雪山,这里分布着M条供滑行的轨道和N个轨道之间的交点(同时也是景点),而且每个景点都有一编号i(1<=i<=N)和一高度Hi. ...
- 字符串MD5加密运算
public static string GetMd5String(string str) { MD5 md5 = MD5.Create(); by ...
- 2017双11海量数据下EagleEye的使命和挑战
摘要: EagleEye作为阿里集团老牌的链路跟踪系统,其自身业务虽不在交易链路上,但却监控着全集团的链路状态,特别是在中间件的远程调用上,覆盖了集团绝大部分的场景,在问题排查和定位上发挥着巨大的作用 ...
- Golang 网络爬虫框架gocolly/colly 二 jQuery selector
Golang 网络爬虫框架gocolly/colly 二 jQuery selector colly框架依赖goquery库,goquery将jQuery的语法和特性引入到了go语言中.如果要灵活自如 ...
- hashCode花式卖萌
声明:这篇博文纯属是最近看源码时闲着没事瞎折腾(好奇心驱动),对实际的应用程序编码我觉得可能没有那么大的帮助,各位亲就当是代码写累了放松放松心情,视为偏门小故事看一看就可以了,别深究. 一.从Obje ...
- 轻量级quill富文本编辑器
因为公司产品需要在移动端编辑文本,所以发现了这个轻量级的好东西,网上也没找到比较好的案例,就自己总结了下,有兴趣的直接复制代码运行看看就知道啦! 下面是quill.js的CDN加速地址: <!- ...
- Git详解之二:Git基础
Git 基础 读完本章你就能上手使用 Git 了(伯乐在线注:如果你对Git还不了解,建议从本Git系列第一篇文章开始阅读).本章将介绍几个最基本的,也是最常用的 Git 命令,以后绝大多数时间里用到 ...
- popupwindow那些坑
1. new PopupWindow(vw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 如果 ...
- SQL基础学习_01_数据库和表
SQL语句及其种类 1. SQL语句分为三类: DDL(Data Definition Language): CREATE.DROP.ALTER; DML(Data Manipulat ...
- js小知识-replace的回调函数
replace() 方法返回一个由替换值替换一些或所有匹配的模式后的新字符串.模式可以是一个字符串或者一个正则表达式, 替换值可以是一个字符串或者一个每次匹配都要调用的函数. 注意:原字符串不会改变. ...