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 ...
随机推荐
- 69.资金管理-税率表管理extjs 页面
1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&quo ...
- http通讯基础
1 . 一个网页包括 JS CSS Html 2 . 状态码:200 正常 302 临时重定向 (类似呼叫转移) 304 未修改,客户端缓存的信息是最新的,无需到服务器重新获取 403 ...
- “国家队爷”杯液体战争AI比赛!!__SymenYang
原帖 这两天一直在搞这个AI,提供的样例更本不是我的风格啊,看不懂更不会改... 所以我自己写了一个AI的平台,现在在不断的修改AI的策略,smart样例还是很容易过的,让line的行走速度变慢一点到 ...
- Centos7基本命令
shell基本命令 linux命令行的组成结构 linux系统命令操作语法格式 命令 空格 参数 空格 文件路径或者需要处理的内容 rm -rf /tmp/* ls -la /home ...
- html表单——使用frameset写一个导航栏效果
主页面: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4 ...
- 345 Reverse Vowels of a String 反转字符串中的元音字母
编写一个函数,以字符串作为输入,反转该字符串中的元音字母.示例 1:给定 s = "hello", 返回 "holle".示例 2:给定 s = "l ...
- vue-cli的创建、基本配置和遇到的问题总结
vue-cli的创建及基本配置 1. 创建 vue-cli 项目 确保本地安装了最新版本的nodejs环境(会自带npm环境); 全局安装vue-cli,命令:npm i -g vue-cli 创建项 ...
- c# winform控件dock属性停造位置、摆放顺序详解
dock : [英文释义- 码头.依靠][winform释义- 获取或设置当前控件依靠到父容器的哪一个边缘.] 用途:多数控件都有这个属性,主要用来设置控件的布局. 但对于不太了解这个属性的朋友来说有 ...
- 前端-Node.js思维导图笔记
看不清的朋友右键保存或者新窗口打开哦!喜欢我可以关注我,还有更多前端思维导图笔记
- [Android]异常9-自定义PopupWindow出现闪屏
背景: 自定义PopupWindow使用时,Android4.0或者一些手机正常使用,Android6.0或者部分手机使用自定义PopupWindow触发事件时,出现闪屏 异常原因: 可能一>A ...