头像

Koal.W


访客:1575

离线:8个月前


活动打卡代码 AcWing 711. 乘法表

Koal.W
8个月前
#include<iostream>

using namespace std;

int main()
{
    int a;
    cin>>a;

    cout<<"1 x"<<' '<<a<<' '<<"="<<' '<<1*a<<endl;
    cout<<"2 x"<<' '<<a<<' '<<"="<<' '<<2*a<<endl;
    cout<<"3 x"<<' '<<a<<' '<<"="<<' '<<3*a<<endl;
    cout<<"4 x"<<' '<<a<<' '<<"="<<' '<<4*a<<endl;
    cout<<"5 x"<<' '<<a<<' '<<"="<<' '<<5*a<<endl;
    cout<<"6 x"<<' '<<a<<' '<<"="<<' '<<6*a<<endl;
    cout<<"7 x"<<' '<<a<<' '<<"="<<' '<<7*a<<endl;
    cout<<"8 x"<<' '<<a<<' '<<"="<<' '<<8*a<<endl;
    cout<<"9 x"<<' '<<a<<' '<<"="<<' '<<9*a<<endl;
    cout<<"10 x"<<' '<<a<<' '<<"="<<' '<<10*a<<endl;
}


活动打卡代码 AcWing 709. 奇数

Koal.W
8个月前
#include<iostream>

using namespace std;

int main()
{
    int a;
    cin>>a;
    for(int i=1;i<=a;i+=2)
    cout<<i<<endl;

    return 0;
}


活动打卡代码 AcWing 709. 奇数

Koal.W
8个月前
#include<iostream>

using namespace std;

int main()
{
    int a;
    cin>>a;
    for(int i=1;i<=a;i+=2)
    cout<<i<<endl;

    return 0;
}


活动打卡代码 AcWing 830. 单调栈

Koal.W
8个月前
#include <iostream>

using namespace std;

const int N = 100010;

int n;
int a[N];
int stk[N], top;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i ++ ) cin >> a[i];

    for (int i = 0; i < n; i ++ )
    {

         while (top > 0 && stk[top] >= a[i]) top -- ;
        if (top > 0) printf("%d ", stk[top]);
        else printf("-1 ");
        stk[ ++ top] = a[i];
    }

    return 0;
}



Koal.W
10个月前

题目描述

blablabla

样例

blablabla

算法1

(暴力枚举) $O(n^2)$

blablabla

时间复杂度分析:blablabla

C++ 代码

#include<iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    int c=a+b;

    cout<<c<<endl;

    return 0;
}

算法2

(暴力枚举) $O(n^2)$

blablabla

时间复杂度分析:blablabla

C++ 代码

blablabla


活动打卡代码 AcWing 826. 单链表

Koal.W
10个月前
#include<iostream>
#include<algorithm>

using namespace std;

const int N=100010;

int head,e[N],ne[N],idx;

void init()
{
    head = -1;
}

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

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

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

int main()
{
    init ();

    int m;
    cin>>m;
    while(m--)
    {
        char op;
        int k,x;
        cin>>op;
        if(op=='H')
        {
            cin>>x;
            add_head(x);
        }
        else if(op=='I')
        {
            cin>>k>>x;
            add_k(k-1,x);
        }
        else
        {
            cin>>k;
            if(!k)head=ne[head];
            else remove(k-1);
        }
    }
    for(int i=head;i!=-1;i=ne[i])cout<<e[i]<<' ';
    cout<<endl;

    return 0;
}


活动打卡代码 AcWing 829. 模拟队列

Koal.W
10个月前
#include<iostream>

using namespace std;

const int N = 100010;

int m;
int q[N],hh,tt=-1;

int main()
{
    cin>>m;

    while (m--)
    {
        string op;
        int x;

        cin>>op;
        if(op=="push")
        {
            cin>>x;
            q[++ tt]=x;

        }
        else if(op=="pop")hh++;
        else if(op=="empty")cout<<(hh<=tt?"NO":"YES")<<endl;
        else cout<<q[hh]<<endl;
    }

    return 0;
}


活动打卡代码 AcWing 828. 模拟栈

Koal.W
10个月前
#include<iostream>

using namespace std;

const int N=100010;
int m;
int stk[N],tt;

int main()
{
    cin>>m;
    while(m--)
    {
        string op;
        int x;

        cin>>op;
        if(op=="push")
        {
            cin>>x;
            stk[++ tt]=x;
        }
        else if(op=="pop")tt --;
        else if(op=="empty")
        {
            if(tt)puts("NO");
            else puts("YES");
        }
        else cout<<stk[tt]<<endl;
    }
    return 0;
}


活动打卡代码 AcWing 798. 差分矩阵

Koal.W
10个月前
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1010;

int n, m, q;
int a[N][N], s[N][N];

int main()
{
    cin >> n >> m >> q;
    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
            scanf("%d", &s[i][j]);

    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
            a[i][j] = s[i][j] - s[i - 1][j] - s[i][j - 1] + s[i - 1][j - 1];

    while (q -- )
    {
        int x1, y1, x2, y2, c;
        scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &c);
        a[x1][y1] += c;
        a[x1][y2 + 1] -= c;
        a[x2 + 1][y1] -= c;
        a[x2 + 1][y2 + 1] += c;
    }

    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
            s[i][j] = a[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];

    for (int i = 1; i <= n; i ++ )
    {
        for (int j = 1; j <= m; j ++ ) printf("%d ", s[i][j]);
        cout << endl;
    }

    return 0;
}




活动打卡代码 AcWing 803. 区间合并

Koal.W
10个月前
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100010;

struct Seg
{
    int l, r;
}seg[N];

bool cmp(Seg a, Seg b)
{
    return a.l < b.l;
}

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i ++ ) scanf("%d%d", &seg[i].l, &seg[i].r);
    sort(seg, seg + n, cmp);

    int res = 0;
    int st = seg[0].l, ed = seg[0].r;
    for (int i = 1; i < n; i ++ )
        if (seg[i].l > ed)
        {
            res ++ ;
            st = seg[i].l, ed = seg[i].r;
        }
        else ed = max(ed, seg[i].r);

    res ++ ;

    printf("%d\n", res);
    return 0;
}