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 sequence








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 ...
随机推荐
- IDEA Spark Streaming Kafka数据源-Consumer
import org.apache.spark.SparkConf import org.apache.spark.streaming.kafka.KafkaUtils import org.apac ...
- [Apple开发者帐户帮助]八、管理档案(1)创建开发配置文件
您可以在开发人员帐户中创建开发配置文件,以便在Xcode中手动签署应用程序时使用. 在开始之前,您需要一个App ID,一个或多个开发证书以及一个或多个已注册的设备.您可以使用Xcode为您管理的Ap ...
- Vue Router的params和query传参的使用和区别
vue页面跳转有两种方式分别是:name和path this.$router.push({name: 'HelloWorld2}) this.$router.push({path: '/hello-w ...
- vagrant使用centos的环境安装..
vagrant这货挺好用的..简要就是, 下好virtualbox, vagrant, 然后下个你需要的box. 然后vagrant box add boxname boxpath就行. 然后在合适的 ...
- Offer收割_5
训练 投入 欲望. ---贾森博尔特 第一题:二分枚举答案,check时候模拟一下即可. 时间复杂度: O(n*logn). 第二题: 描述 小Hi在虚拟世界中有一只小宠物小P.小P有K种属性,每种 ...
- JdbcTemplate:Jdbc模板和数据库元数据
通过 Jdbc .C3P0 .Druid 的使用我们会发现即使我们做了工具的封装,但重复性的代码依旧很多.我们可以通过 JdbcTemplate 即 Jdbc 模板来使我们的代码更加简洁,逻辑更加清晰 ...
- Ajax——瀑布流
基本概念 1.宽度是一致的,高度上参差不齐 2.新增内容优先放置在最矮的地方 核心难点 1.用一个数组存储每列的高度值 2.新值添加到值最小索引上,每次替换更新数组 插件使用 1.$.fn.exten ...
- CSS——伪类
在a标签中运用最多: 1.a:link {color: #FF0000} /* 未访问的链接 */ 2.a:visited {color: #00FF00} /* 已访问的链接 */ 3.a:hove ...
- MyBatis入门2_增删改查+数据库字段和实体字段不一致情况
本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! 当数据库字段和实体bean中属性不一致时 之前数据库P ...
- js弹开页面并调用方法
每次重新写一个功能的时候,都能发现以前写的并不太好,都可以改进,奇怪的是我还是我,为什么曾经的我就想不起来要这么写,比如下面两段代码 历史代码: if (infoTablePage != null) ...