ZOJ 3952 Fibonacci Sequence Chicken Edition
来源:互联网 发布:linux 查找隐藏文件 编辑:程序博客网 时间:2024/05/29 19:15
Year 2017 is the year of chicken, so in this problem we introduce you an interesting programming language: the Chicken Language.
Chicken is an esoteric programming language by Torbjörn Söderstedt, in which “chicken” is the only valid symbol. It is inspired by the paper and the presentation presented at the AAAS humor session by Doug Zongke. We strongly recommend you to watch the presentation after the contest. It’s super fun.
As the original chicken language is a bit complicated, we specially designed the Simplified Chicken Language (SCL) for this problem. An SCL program is consisted of only two kinds of tokens: “c” and new line. The number of “c” tokens in the same line corresponds to an opcode. As the program is executed, it will push/pop values to/from a stack (the stack is empty at the beginning). The opcodes and the descriptions for each instruction of SCL are listed below.
Please keep in mind that the stack of the SCL is 1-based. That is to say, the index of the bottom of the stack is considered to be 1. In the following table, we indicate the integer at the top of the stack as x, and the integer just below the top of the stack as y. We also indicate stack[n] as the integer in the stack whose index is n.
When the program stops, it will print out the integer at the top of the stack as the output.
What you need to do is to write an SCL program which can print out the n-th element of the fibonacci sequence. Recall that a fibonacci sequence is a sequence which satisfies f(1) = f(2) = 1 and f(n) = f(n - 1) + f(n - 2) when n ≥ 3.
As the online judge system of the contest does not support SCL, you’re supposed to print out your SCL program using other languages like C or C++. A specially designed program will then judge the correctness of your output.
解题思路
感觉此题题意就是一个大坑,一直看得云里雾里的。简单可以理解为要求利用 C/C++/etc. 打印出一份满足 Simplified Chicken Language (SCL) 的程序,该 SCL 程序要求能够处理:对于询问 n (
我所编写的 SCL 程序处理逻辑:
- stack 1~30 的位置全部使用 1 (即 8 个
c
) 作为占位格,用于保存斐波那契前 30 项。 - stack 31,32 作为处理用的占位格,利用 Opcode
7
5
,将斐波那契第i-1
项和第i-2
项分别复制到 stack 31,32 的位置,使用 Opcode1
处理, stack 31 保存的即为斐波那契第i
项的结果。 - 再将 stack 31 位置第
i
项的结果利用Opcode7
,5
复制回 stack i 的位置。 - 循环处理出 30 项的结果
代码
#include<bits/stdc++.h>using namespace std;const char c = 'c';int main(){ for(int i=1;i<=30;i++) cout<<string(8, c)<<endl; int idx = 30; for(int i=3;i<=30;i++) { if(i == 3) cout<<string(8, c)<<endl; cout<<string(8, c)<<endl; //x = 31, y = i-2; cout<<string(i-2+7, c)<<endl<<string(31+7, c)<<endl; //stack[x] = stack[y]; cout<<string(5, c)<<endl; //x = 32, y = i-1; cout<<string(i-1+7, c)<<endl<<string(32+7, c)<<endl; //stack[x] = stack[y]; cout<<string(5, c)<<endl; //stack[31] = stack[31] + stack[32]; cout<<string(1, c)<<endl; //x = i, y = 31; cout<<string(31+7, c)<<endl<<string(i+7, c)<<endl; //stack[x] = stack[y]; cout<<string(5, c)<<endl; } // load y = n cout<<string(4, c)<<endl; // x = 31 cout<<string(31+7, c)<<endl; // stack[x] = stack[y] cout<<string(5, c)<<endl;}
- ZOJ 3952 Fibonacci Sequence Chicken Edition
- ZOJ 3952 Fibonacci Sequence Chicken Edition 模拟
- ZOJ 3952 Fibonacci Sequence Chicken Edition(构造/模拟)
- ZOJ3952 Fibonacci Sequence Chicken Edition 【模拟】
- 17th浙大校赛 ZOJ3952 Fibonacci Sequence Chicken Edition【汇编】
- 【ZOJ3952 The 17th Zhejiang University Programming Contest E】【简单构造 模拟 or汇编】Fibonacci Sequence Chicken
- fibonacci sequence
- Fibonacci Sequence
- Fibonacci sequence
- Fibonacci sequence
- SZ Fibonacci Sequence
- 1-2 Fibonacci sequence
- JZOJ1240. Fibonacci sequence
- JZOJ 1240. Fibonacci sequence
- JZOJ.1240. Fibonacci sequence
- zoj 1828 Fibonacci Numbers
- zoj 1828 Fibonacci Numbers
- zoj 2060.Fibonacci Again
- 缓存那些事
- 正则表达式常见匹配案例
- 前台后台数据交互之Servlet & XMLHttpRequest(GET篇)
- 开源 java CMS
- L1-041. 寻找250
- ZOJ 3952 Fibonacci Sequence Chicken Edition
- 抛开table布局,我们也能实现单线边框
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊
- MyEclipse快捷键大全(绝对全)
- ajaxToolkit:AutoCompleteExtender 用法详解
- 【代码笔记】iOS-gif图片播放
- hdu2087 剪花布条
- MyCat中间件:读写分离
- Mybatis与Hibernate的详细对比【持久化框架】