头像

Rnin




离线:2个月前


新鲜事 原文

Rnin
7个月前
开学前学会 dp !冲啊!


新鲜事 原文

Rnin
7个月前
日膜 MY 大佬!


新鲜事 原文

Rnin
7个月前
链表结构 get!



Rnin
7个月前

注意点

输入字符要用 string !!!

代码


#include <string>
#include <iostream>
using namespace std;

const int N = 100000;
int idx, e[N+5], fr[N+5], ne[N+5];

void init()
{
    fr[1]=0;
    ne[0]=1;
    idx=2;
}

void insertL(int x)
{
    fr[idx]=0;
    ne[idx]=ne[0];
    ne[0]=idx;
    fr[ne[idx]]=idx;
    e[idx++]=x;
}

void insertR(int x)
{
    ne[idx]=1;
    fr[idx]=fr[1];
    ne[fr[idx]]=idx;
    fr[1]=idx;
    e[idx++]=x;
}

void insertIL(int x, int k)
{
    fr[idx]=fr[k];
    ne[idx]=k;
    ne[fr[idx]]=idx;
    fr[k]=idx;
    e[idx++]=x;
}

void insertIR(int x, int k)
{
    ne[idx]=ne[k];
    fr[idx]=k;
    fr[ne[idx]]=idx;
    ne[k]=idx;
    e[idx++]=x;
}

void delK(int k)
{
    ne[fr[k]]=ne[k];
    fr[ne[k]]=fr[k];
}

int main() {
    int m;
    init();

    cin >> m;
    while (m--) {
        string s;
        int oper_one, oper_two;
        cin >> s;
        if (s == "L") {
            cin >> oper_one;
            insertL(oper_one);
        }
        else if (s == "R") {
            cin >> oper_one;
            insertR(oper_one);
        }
        else if (s == "D") {
            cin >> oper_two;
            delK(oper_two+1);
        }
        else if (s == "IL") {
            cin >> oper_two >> oper_one;
            insertIL(oper_one, oper_two+1);
        }
        else if (s == "IR") {
            cin >> oper_two >> oper_one;
            insertIR(oper_one, oper_two+1);
        }
    }

    for (int index=ne[0]; index!=1; index=ne[index]) cout << e[index] << " ";

    return 0;
}




Rnin
7个月前

直接给出代码


#include <iostream>
using namespace std;

const int N = 100005;
int head=-1, idx, e[N], ne[N];

void insertHead(int x) {
    e[idx]=x, ne[idx]=head, head=idx++;
}

void insertK(int x, int k) {
    e[idx]=x, ne[idx]=ne[k], ne[k]=idx++;
}

void delK(int k) {
    ne[k]=ne[ne[k]];
}

int main() {
    char c;
    int m, oper_one, oper_two;
    cin >> m;
    while (m--) {
        cin >> c;
        if (c == 'H') {
            cin >> oper_one;
            insertHead(oper_one);
        }
        else if (c == 'D') {
            cin >> oper_two;
            if (!oper_two) head=ne[head];
            delK(oper_two-1);
        }
        else if (c == 'I') {
            cin >> oper_two >> oper_one;
            insertK(oper_one, oper_two-1);
        }
    }

    for (int index=head; index!=-1; index=ne[index]) cout << e[index] << " ";

    return 0;
}




Rnin
7个月前

题目描述

给定 $a, b, p$,求 $a^b$ $mod$ $p$。

基本思路

根据快速幂的思想,可顺势得到快速乘的思想,进而完成代码实现。

C++ 代码


#include <iostream>

#define Ull unsigned long long

using namespace std;

Ull quickMul( Ull a, Ull b, Ull p )
{
    Ull res=0, base=b;
    while ( a )
    {
        if ( a & 1 ) res = (res+base)%p;
        base = (base+base)%p;
        a >>= 1;
    }
    return res;

}

int main()
{
    Ull a, b, p, s;
    cin >> a >> b >> p;
    s = quickMul(a, b, p);
    cout << s << endl;
    return 0;

}



活动打卡代码 AcWing 90. 64位整数乘法

Rnin
7个月前

#include <iostream>

#define Ull unsigned long long

using namespace std;

Ull quickMul( Ull a, Ull b, Ull p )
{
    Ull res=0, base=b;
    while ( a )
    {
        if ( a & 1 ) res = (res+base)%p;
        base = (base+base)%p;
        a >>= 1;
    }
    return res;

}

int main()
{
    Ull a, b, p, s;
    cin >> a >> b >> p;
    s = quickMul(a, b, p);
    cout << s << endl;
    return 0;

}



活动打卡代码 AcWing 89. a^b

Rnin
7个月前

#include <iostream>
#define LL long long
using namespace std;

LL quickPow( LL a, LL b, LL p )
{
    LL res=1, base=a;
    while ( b )
    {
        if ( b & 1 ) res = res*base%p;
        base = base*base%p;
        b >>= 1;
    }
    return res;

}

int main()
{
    LL a, b, p, s;
    cin >> a >> b >> p;
    s = quickPow(a, b, p)%p;
    cout << s << endl;
    return 0;

}




Rnin
7个月前

#include <iostream>
#define LL long long
using namespace std;

LL quickPow( LL a, LL b, LL p )
{
    LL res=1, base=a;
    while ( b )
    {
        if ( b & 1 ) res = res*base%p;
        base = base*base%p;
        b >>= 1;
    }
    return res;

}

int main()
{
    LL a, b, p, s;
    cin >> a >> b >> p;
    s = quickPow(a, b, p)%p;
    cout << s << endl;
    return 0;

}




Rnin
2020-02-23 01:26

蒟蒻报道~~

#include <iostream>
using namespace std;

int main(){
    int n, m; cin >> n >> m;
    cout << n + m;
    return 0;
}