【ZOJ3952 The 17th Zhejiang University Programming Contest E】【简单构造 模拟 or汇编】Fibonacci Sequence Chicken

来源:互联网 发布:手机淘宝开店怎么上架 编辑:程序博客网 时间:2024/05/18 17:41

Fibonacci Sequence Chicken Edition

Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge

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.

OpcodeInstructionDescription1AddPop x and y, and push x + y back to the stack. If there are less than two integers in the stack, the program will crash.2SubtractPop x and y, and push x - y back to the stack. If there are less than two integers in the stack, the program will crash.3ComparePop x and y. If x equals to y then push 1 onto the stack, otherwise push 0 onto the stack. If there are less than two integers in the stack, the program will crash.4LoadLoad one integer from the standard input and push it onto the stack. If there is nothing to load, the program will crash.5CopyPop x and y, and copy stack[y] to stack[x]. If there are less than two integers in the stack, the program will crash. If x or y is out of the range of the current stack, the program will also crash.6JumpPop x and y. If y is not zero, the program will jump to the x-th line and continue to run. If x is larger than the number of lines of the program, the program will stop. If there are less than two integers in the stack, the program will crash. If x is not a positive integer, the program will also crash.7+PushIf the Opcode is larger or equal to 7, push the integer Opcode - 7 onto the stack.

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控制输出这就做完了哦!*/


1 0
原创粉丝点击