头像

冰冷酒

沈阳化工大学




离线:3小时前


最近来访(336)
用户头像
jxj777
用户头像
星辰非昨夜.
用户头像
kuchibi
用户头像
Liuyz.
用户头像
算法先和初中生同步
用户头像
Ja_king
用户头像
史雅文
用户头像
程聿书
用户头像
The_Acute.
用户头像
傻强
用户头像
222222
用户头像
KSzh
用户头像
User-Agent
用户头像
Magic_Zq
用户头像
s7win99
用户头像
徐盛哥哥的刀
用户头像
不再摆烂
用户头像
我很可爱请给我钱
用户头像
玛卡巴卡要AC
用户头像
一缕清风

活动打卡代码 AcWing 100. IncDec序列

冰冷酒
22小时前
#include <bits/stdc++.h>

//#pragma GCC optimize(3, "Ofast", "inline")

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010;

int n, a[N];
int b[N];

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;

    for (int i = 1; i <= n; i ++) cin >> a[i];

    for (int i = 2; i <= n; i ++) b[i] = a[i] - a[i - 1];
    LL numa = 0, numb = 0;

    for (int i = 2; i <= n; i ++)
        if (b[i] > 0) numa += b[i];
        else numb -= b[i];

    cout << min(numa, numb) + abs(numa - numb) << '\n';
    cout << abs(numa - numb) + 1 << '\n';

    return 0;
} 

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~


活动打卡代码 AcWing 107. 超快速排序

冰冷酒
23小时前
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 500010, M = 10;

int n;
int a[N], b[N];
int tr[N];

unordered_map<int, int> m;

int lowbit(int x)
{
    return x & -x;
}

void add(int x, int k)
{
    for (int i = x; i < N; i += lowbit(i))
        tr[i] += k;
}

LL sum(int x)
{
    LL res = 0;
    for (int i = x; i; i -= lowbit(i))
        res += tr[i];
    return res;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    while (cin >> n, n)
    {
        m.clear();
        memset(tr, 0, sizeof(tr));
        for (int i = 1; i <= n; i ++) cin >> a[i], b[i] = a[i];

        sort(b + 1, b + n + 1);
        int idx = 0;
        for (int i = 1; i <= n; i ++) m[b[i]] = ++ idx;

        LL res = 0;

        for (int i = 1; i <= n; i ++)
        {
            add(m[a[i]], 1);
            res += sum(N - 1) - sum(m[a[i]]);
        }

        cout << res << '\n';
    }

    return 0;
}
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~



冰冷酒
23小时前
#include <bits/stdc++.h>

//#pragma GCC optimize(3, "Ofast", "inline")

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010;

int n, m;
LL ans, res;

struct node
{
    string op;
    int x;
}s[N];

void cal(LL &num, string op, int x, int i)
{
    if (op == "AND") num = (num & (x >> i & 1));
    else if (op == "OR") num = (num | (x >> i & 1));
    else num = (num ^ (x >> i & 1));
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n >> m;

    for (int i = 1; i <= n; i ++) 
    {
        string op;
        int x;
        cin >> op >> x;
        s[i] = {op, x};
    }

    for (int i = 30; i >= 0; i --)
    {
        bool leap = false;
        for (int k = 0; k <= 1; k ++)
        {
            LL num = k;
            for (int j = 1; j <= n; j ++)
            {
                string op;
                int x;
                op = s[j].op, x = s[j].x;
                cal(num, op, x, i);
            }
            if (num == 1 && leap == false)
            {
                if (k == 0) ans += (1 << i);
                else if (k == 1 && (1 << i) <= m)
                {
                    m -= (1 << i);
                    ans += (1 << i);
                }
                leap = true;
            }
        }
    }

    cout << ans << '\n';

    return 0;
} 

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~


活动打卡代码 AcWing 96. 奇怪的汉诺塔

冰冷酒
23小时前
#include <bits/stdc++.h>

//#pragma GCC optimize(3, "Ofast", "inline")

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 110;

int T;
int n, x;
ULL f[N], a[N];

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    a[1] = 1;
    for (int i = 2; i <= 64; i ++) a[i] = a[i - 1] * 2 + 1;

    f[1] = 1;
    for (int i = 2; i <= 64; i ++)
    {
        ULL Min = 2e9;
        for (int j = 1; j < i; j ++)
        {
            Min = min(Min, a[i - j] + f[j] * 2);
        }
        f[i] = Min;
    }

    for (int i = 1; i <= 12; i ++) cout << f[i] << '\n';

    return 0;
} 

//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~



#include <bits/stdc++.h>

//#pragma GCC optimize(3, "Ofast", "inline")

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010;

int ans[N], n;
bool st[N];

void dfs(int u)
{
    if (u == n)
    {
        for (int i = 0; i < n; i ++) cout << ans[i] << ' ';
        cout << '\n';
        return ;
    }
    for (int i = 1; i <= n; i ++)
    {
        if (st[i] == false)
        {
            st[i] = true;
            ans[u] = i;
            dfs(u + 1);
            st[i] = false;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;

    dfs(0);

    return 0;
}
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~



#include <bits/stdc++.h>

//#pragma GCC optimize(3, "Ofast", "inline")

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010;

int ans[N];
int n, m;
bool st[N];

void dfs(int u, int x)
{
    if (u == m)
    {
        for (int i = 0; i < m; i ++) cout << ans[i] << ' ';
        cout << '\n';
        return ;
    }
    for (int i = x + 1; i <= n; i ++)
    {
        if (st[i] == false)
        {
            st[i] = true;
            ans[u] = i;
            dfs(u + 1, i);
            st[i] = false;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n >> m;

    dfs(0, 0);

    return 0;
}
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~



#include <bits/stdc++.h>

//#pragma GCC optimize(3, "Ofast", "inline")

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010;

int n;
int ans[N], idx;
bool st[N];
unordered_map<string, int> m;

void dfs(int u, int x)
{
    for (int i = 0; i < u; i ++) cout << ans[i] << ' ';
    cout << '\n';

    if (u == n)
        return ;

    for (int i = x + 1; i <= n; i ++)
    {
        if (st[i] == false)
        {
            st[i] = true;
            ans[u] = i;
            dfs(u + 1, i);
            st[i] = false;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;

    dfs(0, 0);

    return 0;
}
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~


活动打卡代码 工程课 Linux-3.3. homework_3

cd homework_3
touch main.sh
chmod +x main.sh
vim main.sh
#! /bin/bash

read n
read m;

for ((i = 0; i <= n; i ++))
do
    st[$i]=0
done

dfs() {
    if [ $1 -eq $n ]
    then
        m=`expr $m - 1`
        if [ $m -eq 0 ]
        then
            for ((i = 0; i < n; i ++))
            do
                echo -e "${path[$i]} \c"
            done
            echo ''
            return 0
        fi
        return 1
    fi
    local j
    for ((j = 1; j <= n; j ++))
    do
        if [ ${st[$j]} -eq 0 ]
        then
            path[$1]=$j
            st[$j]=1

            if dfs `expr $1 + 1`
            then
                return 0
            fi
            st[$j]=0
        fi
    done
    return 1
}

dfs 0


活动打卡代码 工程课 Linux-3.4. homework_4

cd homework_4
touch main.sh
chmod +x main.sh
vim main.sh

#! /bin/bash

read n < "$1"

sum=0
for ((i = 1; i <= n; i ++))
do
    res=`expr $i \* $i`
    sum=`expr $sum + $res`
done

echo $sum > "$2"



活动打卡代码 工程课 Linux-3.1. homework_1

cd homework_1
touch check_file.sh
chmod +x check_file.sh

#! /bin/bash

if [ $# -ne 1 ] 
then
    echo "arguments not valid"
    exit 1
fi

if [ ! -e "$1" ]
then
    echo "not exist"
    exit 2
fi

if [ -f "$1" ]
then
    echo "regular file"
fi

if [ -d "$1" ]
then
    echo "directory"
fi

if [ -r "$1" ]
then
    echo "readable"
fi

if [ -w "$1" ]
then
    echo "writable"
fi

if [ -x "$1" ]
then
    echo "executable"
fi