Codeforces Round #423 (Div. 2) A-C

A. Restaurant Tables

这里看错题意还wa了两发....

按题意模拟就行了 水题

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;

int main() {
    //FIN
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    int ans = 0;
    int flag = 0;
    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        if(x == 1) {
            if(a >= 1) a--;
            else if(b >= 1){
                b--;
                flag++;
            }
            else if(flag >= 1) {
                flag--;
            }
            else ans++;
        }
        else {
            if(b >= 1) b--;
            else ans += 2;

        }
    }
    printf("%d
", ans);
    return 0;
}

  

B. Black Square

问补全一个B组成的正方形至少还要多少个B

直接记录四个角的值然后就差不多了

一个B都没有的话直接输出1就行

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;

char mp[105][105];

int main() {
    //FIN
    int n, m;
    while(~scanf("%d%d", &n, &m)) {
         for(int i = 0; i < n; i++) scanf("%s", mp[i]);
         //for(int i = 0; i < n; i++) cout << mp[i] << endl;
         int minx = 105, miny = 105, maxx = -1, maxy = -1;
         int cnt = 0;
         for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if(mp[i][j] == 'B') {
                    cnt++;
                    minx = min(minx, j);
                    miny = min(miny, i);
                    maxy = max(maxy, i);
                    maxx = max(maxx, j);
                }
            }
         }
         if(cnt == 0) {
            printf("1
");
            continue;
         }

         int c = maxx - minx + 1;
         int k = maxy - miny + 1;
         int mx = max(c, k);
         int ans = mx * mx - cnt;
         if(mx > n || mx > m) {
            printf("-1
");
            continue;
         }
         else {
            printf("%d
", ans);
         }

    }

    return 0;
}

  

C. String Reconstruction

题意:告诉你一些字符串在原字符串中出现的位置 然你输出原字符串 没告诉你的地方就输出a

直接模拟 但是要注意剪枝 访问过的久不用再访问了

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;

const int maxn = 2000006;

char s[maxn];
char op[maxn];

int main() {
    //FIN
    int n;
    scanf("%d", &n);
    memset(s, 'a', sizeof(s));
    int mxpos = 0;
    for(int i = 1; i <= n; i++) {
        scanf("%s", op);
        int k;
        int tmp = -INF;
        int len = strlen(op);
        scanf("%d", &k);
        for(int j = 1; j <= k; j++) {
            int pos;
            scanf("%d", &pos);
            mxpos = max(mxpos, pos + len);
            for(int z = max(tmp, pos); z < pos + len; z++) {
                s[z] = op[z - pos];
            }
            tmp = pos + len;
        }
    }
    for(int i = 1; i <= mxpos - 1; i++) printf("%c", s[i]);
    printf("
");



    return 0;
}

  

原文地址:https://www.cnblogs.com/Hyouka/p/7327846.html