HDU - 3556 - Continued Fraction
先上题目:
Continued Fraction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 332 Accepted Submission(s): 106
One day Dumbear found that each number can be expressed as a continued fraction. See below.
Formally, we say a number k can be expressed as a continued faction if
where a0, a1, …, an are positive integers except that a0 maybe be 0 and an cannot be 1.
Dumbear also found a sequence which looks like the Farey sequence. Initially the sequenceand if we insert an elementbetween all the two adjacent element,in Di, then we get a sequence Di+1. So you can seeandAssume initially you are on the elementin D0, and if now you are on the element k in Di, then if you go left(‘L’)(or right(‘R’)) you will be on the left(or right) element of k in Di+1. So a sequence composed of ‘L’ and ‘R’ denotes a number. Such as ‘RL’ denotes the number
Now give you a sequence composed of ‘L’ and ‘R’, you should print the continued fraction form of the number. You should use ‘-‘ to show the vinculum(the horizontal line), you should print one space both in front and back of ‘+’, and all parts up or down the vinculum should be right aligned. You should not print unnecessary space, ‘-‘ or other character. See details in sample.
For each test case, there is a single line contains only a sequence composed of ‘L’ and ‘R’. The length of the sequence will not exceed 10000.
The input terminates by end of file marker.
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define MAX 10002
#define PUTS(M,x) for(int k=0;k<M;k++) putchar(x)
#define ll long long
using namespace std; char c[MAX];
int l;
ll a[MAX];
char ss[MAX<<][];
int len[MAX];
int tot;
typedef struct{
ll fz,fm;
}fs; fs A[],p; void cons(int l){
if(c[]=='L'){
a[]=; a[]=; tot=;
}else{
a[]=; tot=;
}
for(int i=;i<l;i++){
if(c[i]==c[i-]) a[tot]++;
else{
a[tot]--;
a[++tot]=;
}
}
tot++;
} int main()
{
int M;
//freopen("data.txt","r",stdin);
while(scanf("%s",c)!=EOF){
l=strlen(c);
// A[0].fz=0; A[0].fm=1;
// A[1].fz=1; A[1].fm=1;
// A[2].fz=1; A[2].fm=0;
// for(int i=0;i<l;i++){
// if(c[i]=='L'){
// A[2]=A[1];
// }else{
// A[0]=A[1];
// }
// A[1].fz=A[0].fz+A[2].fz;
// A[1].fm=A[0].fm+A[2].fm;
// }
// tot=0;
// p=A[1];
// while(1){
// a[tot]=p.fz/p.fm;
// sprintf(ss[tot],"%I64d",a[tot]);
// tot++;
// p.fz=p.fz%p.fm;
// if(p.fz==0) break;
// else if(p.fz==1){
// a[tot]=p.fm;
// sprintf(ss[tot],"%I64d",a[tot]);
// tot++;
// break;
// }
// swap(p.fz,p.fm);
// }
cons(l);
for(int i=;i<tot;i++) sprintf(ss[i],"%I64d",a[i]);
len[tot-]=strlen(ss[tot-]);
len[tot-]=strlen(ss[tot-]) + + strlen(ss[tot-]);
for(int i=tot-;i>=;i--){
len[i]=strlen(ss[i]) + + len[i+];
} // for(int i=0;i<tot;i++) printf("%I64d ",a[i]);
// printf("\n");
// for(int i=0;i<tot;i++) printf("%d ",len[i]);
// printf("\n");
M=len[];
for(int i=;i<tot-;i++){
PUTS(M-,' '); putchar(''); putchar('\n');
PUTS(M-len[i],' ');
printf("%s + ",ss[i]);
PUTS(len[i+],'-');
putchar('\n');
}
PUTS(M-(int)strlen(ss[tot-]),' ');
printf("%s",ss[tot-]);
printf("\n");
}
return ;
}
/*3556*/
HDU - 3556 - Continued Fraction的更多相关文章
- CSUOJ 1638 Continued Fraction
1638: Continued Fraction Time Limit: 1 Sec Memory Limit: 128 MB Description Input Output Sample Inp ...
- hdu 6223 Infinite Fraction Path
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6223 题意:给定长度为n的一串数字S,现在要按照一种规则寻找长度为n的数字串,使得该数字串的字典序最大 ...
- HDU - 6223 Infinite Fraction Path (倍增+后缀数组)
题意:给定一个长度为n(n<=150000)的字符串,每个下标i与(i*i+1)%n连边,求从任意下标出发走n步能走出的字典序最大的字符串. 把下标看成结点,由于每个结点有唯一的后继,因此形成的 ...
- Continued Fractions CodeForces - 305B (java+高精 / 数学)
A continued fraction of height n is a fraction of form . You are given two rational numbers, one is ...
- CF 305B——Continued Fractions——————【数学技巧】
B. Continued Fractions time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 2014-2015 ACM-ICPC East Central North America Regional Contest (ECNA 2014) A、Continued Fractions 【模拟连分数】
任意门:http://codeforces.com/gym/100641/attachments Con + tin/(ued + Frac/tions) Time Limit: 3000/1000 ...
- 欧拉工程第65题:Convergents of e
题目链接 现在做这个题目真是千万只草泥马在心中路过 这个与上面一题差不多 这个题目是求e的第100个分数表达式中分子的各位数之和 What is most surprising is that the ...
- BCTF warmup 50
这是一道关于RSA的解密题:首先,我们要明白,通常是公钥加密.私钥解密,私钥签名.公钥验证.这个题目中给出的是一个公钥和一段密文. 刚开始一直以为和验证签名有关,费劲脑汁也想不出来怎么办.下面介绍些思 ...
- (Problem 57)Square root convergents
It is possible to show that the square root of two can be expressed as an infinite continued fractio ...
随机推荐
- HDU3487 Play with Chain splay 区间反转
HDU3487 splay最核心的功能是将平衡树中的节点旋转到他的某个祖先的位置,并且维持平衡树的性质不变. 两个操作(数组实现) cut l,r, c把[l,r]剪下来放到剩下序列中第c个后面的位置 ...
- Tornado集成Apscheduler定时任务
熟悉Python的人可能都知道,Apscheduler是python里面一款非常优秀的任务调度框架,这个框架是从鼎鼎大名的Quartz移植而来. 之前有用过Flask版本的Apscheduler做定时 ...
- Unity基本操作
主要内容: C#学习 Unity项目 打砖块:BreakBricks Unity操作 Unity操作: 调试 碰撞体 触发器 视角 键盘视角平移 光照贴图 游戏对象Gameobject 访问对象 实体 ...
- 关于C++ const 变量
const 的全局变量是储存在一个只读数据段中,虽然你可以定义一个指向它的指针,却会在运行时,在对该地址赋值的时候发生运行错误,而局部的const变量是储存在栈中的,离开作用域后同样会被释放,并且可以 ...
- 关于华为手机Log.d打印不出来log的问题
http://blog.csdn.net/picasso_l/article/details/52489560 拨号,进入后台设置,进行操作.
- animation仿进度条
animation:使用的好可以有很多酷炫效果 仿进度条效果.
- JS——选择水果
注意点: 1.select标签size属性显示选项数组,multiple属性可以多选 2.原select节点下的子节点在移动到其他selec标签下的时候,其原来的select标签下子节点长度在发生变化 ...
- java攻城师之路--复习java web之request_respone
Servlet技术 两条主线1.HTTP协议 2.Servlet生命周期 init() 方法中参数 ServletConfig 对象使用通过ServletConfig 获得 ServletContex ...
- Java_Web三大框架之Hibernate+jsp+selvect+HQL登入验证
刚开始接触Hibernate有些举手无措,觉得配置信息太多.经过一个星期的适应,Hibernate比sql简单方便多了.下面做一下Hibernate+jsp+selvect+HQL登入验证. 第一步: ...
- HDU_1026_Ignatius and the Princess I_BFS(保存路径)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...