首页 > 编程语言 >第九届福建省大学生程序设计竞赛-重现赛(感谢承办泉州师范学院)

第九届福建省大学生程序设计竞赛-重现赛(感谢承办泉州师范学院)

时间:2023-04-24 22:40:04浏览次数:35  
标签:第九届 师范学院 int long abc mp 程序设计 include Mod


In the distant space, there is a technologically advanced planet.

One day they provided the Earth with a code that could achieve the ultimate meaning of the universe. People were very happy, but found that this code can only run on computers with a word length of 47 bits. As a good computer scientist, you need to implement a tool to simulate running this code on our computer.

This tool needs to simulate the following instructions:

“def x n” : define a unsigned 47 bits integer variable named x, with initial value n, n is an integer in [0, 2^47-1]

“add x y” : means x = x + y

“sub x y” : means x = x - y

“mul x y” : means x = x * y

“div x y” : means x = x / y, we guarantee y is not zero

“mod x y” : means x = x % y, we guarantee y is not zero

When the result of addition and multiplication cannot be represented by 47 bits, the part above 47 bits is truncated.

When the result of subtraction is less than zero, the result should add 2^47.

The name of each variable only contains letters and the length does not greater than 20.

Input
Contains multiple lines of input, one instruction per line.

Output
For each instruction, output the value of the first argument after calculation. For example, “def abc 100”, then your output will be “abc = 100” in a line with no quotation marks.

See Sample Output for more information.

Sample Input
def six 6
def abc 1
def bcd 0
sub bcd abc
add abc six
def universe 0
mul abc six
add universe abc
div bcd six
mod bcd abc
Sample Output
six = 6
abc = 1
bcd = 0
bcd = 140737488355327
abc = 7
universe = 0
abc = 42
universe = 42
bcd = 23456248059221
bcd = 5

题目不难,但有坑点。。。。
(交了10发。。。都没过。。。
编译器也有一点问题。。(不说了。。

注意使用 unsigned long long 储存,
但是遇到减法时候,要先加 Mod, 因为 可能会由于减法变成负数。。。。
注意这一点应该就没有什么问题了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 2000005
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;

ll read() {
    ll x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch>'9') {
        if (ch == '-') {
            f = -1;
        }
        ch = getchar();
    }
    while (ch >= '0'&&ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

ll quickpow(ll a, ll b) {
    ll ans = 1;
    while (b > 0) {
        if (b % 2)ans = ans * a;
        b = b / 2;
        a = a * a;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}


bool cmp(int a, int b) {
    return a > b;
}

ll ves[maxn];
void revs() {
    for (ll i = 1; i <= 1000000; i++) {
        ves[i] = quickpow(i, mod - 2);
    }
}

map<string, ull>mp;
//ull Mod = quickpow(2ull, 47ull);

int main() {
    ios::sync_with_stdio(false);
    string con;
    ull Mod = 1;
    for (int i = 1; i <= 47; i++)Mod = Mod * 2;

    //cout << Mod << endl;
    while (cin >> con) {
        if (con == "def") {
            string de;
            ull x;
            cin >> de >> x;
        //  x = x % Mod;
            mp[de] = x;
            cout << de << ' ' << '=' << ' ' << x << endl;
            continue;
        }
        else if (con == "add") {
            string m, n;
            cin >> m >> n;
        //  mp[m] = (mp[n] % Mod + mp[m] % Mod + Mod) % Mod;
            mp[m] += mp[n];
            mp[m] %= Mod;
            cout << m << ' ' << '=' << ' ' << mp[m] << endl;
        }
        else if (con == "sub") {
            string m, n;
            cin >> m >> n;
            mp[m] += Mod - mp[n];
            if (mp[m] >= Mod) {
                mp[m] -= Mod;
            }
            cout << m << ' ' << '=' << ' ' << mp[m] << endl;
        }
        else if (con == "mul") {
            string m, n;
            cin >> m >> n;
            mp[m] = ((mp[m]) * (mp[n]));
            mp[m] = mp[m] % Mod;
            cout << m << ' ' << '=' << ' ' << mp[m] << endl;
        }
        else if (con == "div") {
            string m, n;
            cin >> m >> n;
            mp[m] /= mp[n];
            cout << m << ' ' << '=' << ' ' << mp[m]  << endl;
        }
        else if (con == "mod") {
            string m, n;
            cin >> m >> n;
            mp[m] = mp[m] % mp[n];
            cout << m << ' ' << '=' << ' ' << mp[m]  << endl;
        }
    }
}


标签:第九届,师范学院,int,long,abc,mp,程序设计,include,Mod
From: https://blog.51cto.com/u_15657999/6221922

相关文章

  • 第九届福建省大学生程序设计竞赛-重现赛(感谢承办泉州师范学院) spfa变形
    Xzzisachildwithsevereprocrastinations.Thenewsemesterbegins,Hestillhasalotofhomeworktodo.Now,heneedsyourhelp.Asthebestfriend,youaregoodatmath.So,youwillhelphimdosomemathhomework.NowXzzwantstogotoyourhome.Y......
  • 2023年团体程序设计天梯赛 题解
    仅更新L1,L2随后写**更好的阅读体验:2023年团体程序设计天梯赛题解**L1-1最好的文档有一位软件工程师说过一句很有道理的话:“Goodcodeisitsownbestdocumentation.”(好代码本身就是最好的文档)。本题就请你直接在屏幕上输出这句话。输入格式:本题没有输入。输出格式:在一行中输出......
  • 2023年团体程序设计天梯赛 题解
    仅更新L1,L2随后写**更好的阅读体验:2023年团体程序设计天梯赛题解**L1-1最好的文档有一位软件工程师说过一句很有道理的话:“Goodcodeisitsownbestdocumentation.”(好代码本身就是最好的文档)。本题就请你直接在屏幕上输出这句话。输入格式:本题没有输入。输出格式:在一行中输出......
  • 2023年团体程序设计天梯赛 题解
    仅更新L1,L2随后写L1-1最好的文档点击查看本题有一位软件工程师说过一句很有道理的话:“Goodcodeisitsownbestdocumentation.”(好代码本身就是最好的文档)。本题就请你直接在屏幕上输出这句话。输入格式:本题没有输入。输出格式:在一行中输出Goodcodeisitsownbest......
  • 2023GPLT团体程序设计天梯赛 记录
    排名个人全国排名: 4391(共1w7)个人全校排名: 第3名个人21级排名: 第2名(第一名是ztm哥,顶级混分手,狂砍181分)队伍排名:河南省 第23,银牌,话说为啥去年我会写第九(分数得分:161题目情况:L1-01L1-02L1-03L1-04L1-05L1-06L1-07L1-08L2-01L2-02......
  • JSP程序设计_全程_老师笔记
    ​2.21笔记 一、网页的组成元素      网页一般是由内容、样式和布局、动效三部分组成的。            内容(HTML)主要指的是页面的文字、按钮button、图片img、视频video、音频audio等等            样式和布局(CSS)指的是内容的大小、颜......
  • 青岛市程序设计竞赛冲刺①
    2021年青岛市小学组第三题原题: 解题代码:#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>usingnamespacestd;constintN=5e2+5,dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};intn,m,vis[N][N],ans=0;charc......
  • pta程序设计辅助平台练习题
    一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下:首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值Z;最后按照以下关系对应Z值与校验码M的值:Z:012345678910M:10X98765432 ......
  • 团体程序设计天梯赛 L1-064 估值一亿的AI核心代码 题解
    思路L1-064估值一亿的AI核心代码题意有一点不太清晰的,就是原文中的'I',无论是否是单独的,都不能变为小写。如果是单独的'I'再被转化为'you'。这种模拟题就需要每个的分分清清楚楚的,不要都揉到一块儿,容易写错。具体还有些需要注意的在代码里注释着了。代码#include<iostream>......
  • 华中农业大学2023年十二届程序设计竞赛(补题)
    题目地址B.写信题意:有n个信封和n封信,问全部装错有多少种可能Solution全错排问题,对于i=k的情况,我们可以从i=k-1和i=k-2转移过来一种是k-1个全错排,然后从前面k-1个选出一个信封与第k个交换另一种是任选一个j,有1<=j<=k-1放在k,这样除了k和j以外还有k-2个数进行全错位排列,这样我......