zoukankan      html  css  js  c++  java
  • #69. 新年的QAQ

    题目描述

    http://uoj.ac/problem/69

    题解

    做之前瞄了先一眼题解,get到了核心部分

    因为给的运算符很不靠谱,所以考虑实现一个靠谱的运算符

    题解的"正常"做法是按照行号来编号,并不是很明白

    正常做法(自己写的):如果要实现c=a+b,那么搞一个d=c-a-b判断d是否为0来跳转即可,因为判断0的跳转是100%正确的,而且如果结果是错的但d=0的几率可以忽略不计,a%b同理

    于是就没了

    更加正常的做法:实现c=a+b,把运算做两次之后判断是否相等,给的逻辑运算符很辣鸡,所以直接用两次的差判断0即可

    code

    #include <bits/stdc++.h>
    #define fo(a,b,c) for (a=b; a<=c; a++)
    #define fd(a,b,c) for (a=b; a>=c; a--)
    #define ll long long
    //#define file
    using namespace std;
    
    int main()
    {
        #ifdef file
        freopen("prog.txt","w",stdout);
        #endif
        
        cout<<"input n"<<endl;
    	cout<<"input m"<<endl;
    	cout<<"a = 0"<<endl;
    	cout<<"b = 1"<<endl;
    	cout<<"c = a + b"<<endl;
    	cout<<"z = c - a"<<endl;
    	cout<<"z = z - b"<<endl;
    	cout<<"if z goto 5"<<endl;
    	cout<<"x = c % m"<<endl;
    	cout<<"y = c / m"<<endl;
    	cout<<"z = y * m"<<endl;
    	cout<<"z = z + x"<<endl;
    	cout<<"z = z - c"<<endl;
    	cout<<"if z goto 9"<<endl;
    	cout<<"c = x"<<endl;
    	cout<<"a = b"<<endl;
    	cout<<"b = c"<<endl;
    	cout<<"c = n - 1"<<endl;
    	cout<<"z = c + 1"<<endl;
    	cout<<"z = z - n"<<endl;
    	cout<<"if z goto 18"<<endl;
    	cout<<"n = c"<<endl;
    	cout<<"if n goto 5"<<endl;
    	cout<<"output a"<<endl;
    }
    
  • 相关阅读:
    ubuntu上virtualbox无法找到usb设备【解决】
    try or install Ubuntu on MeegoPad T01
    213. 打家劫舍 II
    198. 打家劫舍
    70. 爬楼梯
    62. 不同路径
    idea | gitee 码云
    数据库 | 远程连接centos7上数据库
    JSP && Servlet | 上传图片到数据库
    bootstrap | 模态框
  • 原文地址:https://www.cnblogs.com/gmh77/p/13509945.html
Copyright © 2011-2022 走看看