Codeforces DeltixRoundSpring2021(Div.1+Div.2) 1523

Codeforces Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)

传送门

A. Game of Life

思路

这题代码写的比较丑。
主要思路就是判断两个1之间如何填充,暴力输出即可。

Code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<ll> VLL;
typedef vector<VI> VII;
typedef vector<VII> VIII;
typedef pair<int, int> PII;

#define rep(i,a,b) for(int i = (a); i <= (b); i ++)
#define per(i,a,b) for(int i = (a); i >= (b); i --)
#define mkp(a,b) make_pair(a,b)

//#define __int128 ll

const int N = 1e3 + 5;
//const int M = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double EPSS = 1e-12;
const double PI = acos(-1);
//const double PI = 3.14;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = 233333333;
//const int dx[] = {-1, 1, 0, 0};
//const int dy[] = {0, 0, -1, 1};

//const int dx[] = { 1, 0, 0,-1};
//const int dy[] = { 0,-1, 1, 0};

char ch[N];

int main()
{
    int T;
    scanf("%d", &T);
    while(T --)
    {
        int n, m;
        scanf("%d%d", &n, &m);
        scanf("%s", ch+1);
        int flag=0;
        rep(i,1,n)
        {
            if(ch[i]=='1')
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            printf("%s\n", ch+1);
            continue;
        }
        int st=1;
        rep(i,1,n)
        {
            if(ch[i]=='1')
            {
                int one=min(m,i-1);
                rep(j,1,i-one-1)
                    printf("0");
                rep(j,i-one,i)
                    printf("1");
                st=i;
                break;
            }
        }
        rep(i,st+1,n)
        {
            if(ch[i]=='1')
            {
                int one=min(m,(i-st-1)/2);
                if((i-st)%2==1)
                {
                    rep(j,st+1,st+one)
                        printf("1");
                    rep(j,st+one+1,i-one-1)
                        printf("0");
                    rep(j,i-one,i)
                        printf("1");
                }
                else
                {
                    rep(j,st+1,st+one)
                        printf("1");
                    rep(j,st+one+1,i-one-1)
                        printf("0");
                    rep(j,i-one,i)
                        printf("1");
                }
                st=i;
            }
        }
        int one=min(m,n-st);
        rep(j,st+1,st+one)
            printf("1");
        rep(j,st+one+1,n)
            printf("0");
        printf("\n");
    }
    return 0;
}

B. Lord of the Values

思路

这题比赛时候挂了,没想出来,然后看了题解,md,亏了。
我真傻,真的,我单知道n是偶数会有坑,就是没想到。
假设有数a[i], a[i+1],则经过:
1 i i+1 a[i]+a[i+1] a[i+1]
2 i i+1 a[i]+a[i+1] -a[i]
1 i i+1 a[i+1]        -a[i]
2 i i+1 a[i+1]        -a[i]-a[i+1]
1 i i+1 -a[i]           -a[i]-a[i+1]
2 i i+1 -a[i]           -a[i+1]
后,即可变为-a[i], -a[i+1]。两两配对操作即可。

Code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<ll> VLL;
typedef vector<VI> VII;
typedef vector<VII> VIII;
typedef pair<int, int> PII;

#define rep(i,a,b) for(int i = (a); i <= (b); i ++)
#define per(i,a,b) for(int i = (a); i >= (b); i --)
#define mkp(a,b) make_pair(a,b)

//#define __int128 ll

const int N = 5e5 + 5;
//const int M = 30 + 5;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double EPSS = 1e-12;
const double PI = acos(-1);
//const double PI = 3.14;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = 233333333;
//const int dx[] = {-1, 1, 0, 0};
//const int dy[] = {0, 0, -1, 1};

//const int dx[] = { 1, 0, 0,-1};
//const int dy[] = { 0,-1, 1, 0};

int main() {
    int T;
    scanf("%d", &T);
    while (T --) {
        int n;
        scanf("%d", &n);
        for (int i=0; i<n; ++i) {
            int tmp;
            scanf("%d", &tmp);
        }
        printf("%d\n", 3 * n);
        for (int i=1; i<=n/2; ++i) {
            printf("%d %d %d\n", 1, i, i + n/2);
            printf("%d %d %d\n", 2, i, i + n/2);
            printf("%d %d %d\n", 1, i, i + n/2);
            printf("%d %d %d\n", 2, i, i + n/2);
            printf("%d %d %d\n", 1, i, i + n/2);
            printf("%d %d %d\n", 2, i, i + n/2);
        }
    }
    return 0;
}

C. Compression and Expansion

思路

亏了,这题不难,但是B卡题直接就挂机了。
如果a[i]==1,则直接在上一位后面添加“.1”;
如果a[i]!=1,则向前找最近的满足a[i]==x+1,将该位修改为a[i]即可。

Code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<ll> VLL;
typedef vector<VI> VII;
typedef vector<VII> VIII;
typedef pair<int, int> PII;

#define rep(i,a,b) for(int i = (a); i <= (b); i ++)
#define per(i,a,b) for(int i = (a); i >= (b); i --)
#define mkp(a,b) make_pair(a,b)

//#define __int128 ll

const int N = 5e5 + 5;
//const int M = 30 + 5;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double EPSS = 1e-12;
const double PI = acos(-1);
//const double PI = 3.14;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = 233333333;
//const int dx[] = {-1, 1, 0, 0};
//const int dy[] = {0, 0, -1, 1};

//const int dx[] = { 1, 0, 0,-1};
//const int dy[] = { 0,-1, 1, 0};

int main() {
    int T;
    scanf("%d", &T);
    while (T --) {
        int n;
        scanf("%d", &n);
        int tmp;
        scanf("%d", &tmp);
        printf("1\n");
        int last[n];
        last[0] = tmp;
        int pos=1;
        for (int i=1; i<n; ++i) {
            scanf("%d", &tmp);
            if (tmp == 1) {
                last[pos++] = tmp;
            }
            else {
                for (int j=pos-1; j>=0; --j) {
                    if (tmp == last[j]+1) {
                        pos = j;
                        last[pos++] = tmp;
                        break;
                    }
                }
            }
            for (int j=0; j<pos; ++j) {
                printf("%d%c", last[j], ".\n"[j==pos-1]);
            }
        }
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值