【ZOJ3952 The 17th Zhejiang University Programming Contest E】【简单构造 模拟 or汇编】Fibonacci Sequence Chicken
来源:互联网 发布:手机淘宝开店怎么上架 编辑:程序博客网 时间:2024/05/18 17:41
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.
The paper and the presentation by Doug Zongke.
From https://www.youtube.com/watch?v=yL_-1d9OSdk
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.
Input
There is no input for your C/C++/etc. program.
For your SCL program, only one integer n (1 ≤ n ≤ 30) will be given in the standard input, indicating the index of the element in the fibonacci sequence.
Output
Your C/C++/etc. program should output your SCL program.
Please output your SCL program in the correct format. If your program contains tokens other than "c" or new line (for example, space), or you print extra empty lines at the end of your output, you will get a "wrong answer" verdict.
Also, your SCL program should contain no more than 104 "c" tokens, and your SCL program can execute at most 103 lines of code for each SCL test case, or you will get a "wrong answer" verdict.
Note that if your SCL program crashes due to various reasons, you will still get a "wrong answer" verdict as this problem is special judged.
Your SCL program should print out only one integer f(n), which is the n-th element of the fibonacci sequence.
Sample Output
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Hint
Please note that the sample output is only to show you the output format, and it is NOT A CORRECT ANSWER!
What the sample SCL program do is to read an integer from the standard input and check if the integer equals to 2. If it does, then print out the integer directly, otherwise add 2 to the integer and print it out. You can try to figure out how this SCL program works, as it may help you to understand the problem better.
Author: WENG, Caizhi
Source: The 17th Zhejiang University Programming Contest Sponsored by TuSimple
#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<math.h>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }#define MS(x, y) memset(x, y, sizeof(x))#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }const int N = 0, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;template <class T1, class T2>inline void gadadd(T1 &a, T2 b) { a = (a + b) % Z; }int casenum, casei;void op(int num){for (int i = 1; i <= num; ++i)putchar('c');puts("");}void add(int num){num += 7;for (int i = 1; i <= num; ++i)putchar('c');puts("");}int main(){//初始化add(1); add(1);//求出斐波那契每一项for (int i = 3; i <= 30; ++i){add(1); add(1);add(i - 2); add(i); op(5);add(i - 1); add(i + 1); op(5);op(1);}add(1);//31行,占位置op(4);//读入n,在栈的第32项add(31);op(5);add(500);add(500);op(6);return 0;}/*【trick&&吐槽】老师让我带一个学妹,于是队伍战斗力下降很多。前期敲了6题有点懵逼,这题的时候我校Big Zhu God AC了,然后狂拍桌子。让我以为是神题于是感觉来不及做了。最后时间没办法,懂题意之后秒会,7分钟敲完。可惜当时只有5分钟了,于是遗憾8题。这题好蠢啊!搜了下发现大家做法都很麻烦。233333 难道只有我的想法这么干脆吗~~【题意】http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3952题意就是用汇编的栈实现斐波那契前30项中任一项的计算【分析】<1> 用Push 和 Copy 生成斐波那契每一项<2> 用Load 读n,直接copy到栈顶<3> 用Jump控制输出这就做完了哦!*/
- 【ZOJ3952 The 17th Zhejiang University Programming Contest E】【简单构造 模拟 or汇编】Fibonacci Sequence Chicken
- 17th浙大校赛 ZOJ3952 Fibonacci Sequence Chicken Edition【汇编】
- The 16th Zhejiang University Programming Contest - E
- ZOJ3952 Fibonacci Sequence Chicken Edition 【模拟】
- 【ZOJ3950 The 17th Zhejiang University Programming Contest C】【简单日期模拟】How Many Nines 区间9个数计数
- The 12th Zhejiang University Programming Contest
- The 14th Zhejiang University Programming Contest
- The 14th Zhejiang University Programming Contest
- [The 14th Zhejiang University Programming Contest]
- The 15th Zhejiang University Programming Contest
- The 15th Zhejiang University Programming Contest
- The 15th Zhejiang University Programming Contest
- The 15th Zhejiang University Programming Contest
- The 16th Zhejiang University Programming Contest-
- 【ZOJ3948 The 17th Zhejiang University Programming Contest A】【暴力 or 讨论】Marjar Cola 瓶盖饮料换可乐
- The 11th Zhejiang University Programming Contest / 解题报告 4.3
- The 11th Zhejiang University Programming Contest - C/ Chinese Zodiac
- The 11th Zhejiang University Programming Contest - G/ Gaussian Prime
- 关于MVC、MVP架构
- MySQL数据库(入门)(二)
- 操作系统原理:动态内存分配
- java学习笔记(十四)冒泡与选择排序
- oc学习-4.12
- 【ZOJ3952 The 17th Zhejiang University Programming Contest E】【简单构造 模拟 or汇编】Fibonacci Sequence Chicken
- 听过讲座《如何敲开世界500强企业大门》的感想
- HDU1875通畅工程再续
- 存储管理之页式、段式、段页式存储 以及 优缺点
- Android开发中,那些让你相见恨晚的方法、类或接口
- Shader Learing(Basic Lighting And Texturing篇)
- 前端多页面情况下id的命名与初始化
- zookeeper
- Oracle BEGIN END 【整理】