• Codeforces Round #556 (Div. 2)


    比赛链接

    A

    贪心

    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <set>
    using namespace std;
    const int N = 1005;
    int a[N], b[N];
    int n, m, bou, res;
    inline bool rule(int x, int y){
    	return x > y;
    }
    int main(){
    	scanf("%d%d%d", &n, &m, &bou);
    	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    	for(int i = 1; i <= m; ++i) scanf("%d", &b[i]);
    	sort(a + 1, a + n + 1); sort(b + 1, b + m + 1, rule);
    	int cnt = b[1] > a[1] ? bou / a[1] : 0;
    	res = cnt * b[1] - cnt * a[1] + bou; 
    	printf("%d", res);
    	return 0;
    }
    

    B

    贪心。。

    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <set>
    using namespace std;
    const int N = 55;
    int n;
    bool map[N][N], col[N][N];
    inline void print(int x, int y){
    	if(!(map[x][y] & map[x + 1][y] & map[x + 1][y - 1]
    	 & map[x + 1][y + 1] & map[x + 2][y])){
    		printf("NO
    "); exit(0);
    	}
        map[x][y] = map[x + 1][y] = map[x + 1][y - 1]
    	= map[x + 1][y + 1] = map[x + 2][y] = 0;
    }
    int main(){
    	scanf("%d", &n);
    	char str[N];
    	for(int i = 1; i <= n; ++i){
    		scanf("%s", str + 1);
    		for(int j = 1; j <= n; ++j){
    			map[i][j] = (str[j] == '.');
    		}
    	}
    	for(int i = 1; i <= n; ++i){
    		for(int j = 1; j <= n; ++j){
    			if(map[i][j]) print(i, j);
    		}
    	}
    	printf("YES
    ");
    	return 0;
    }
    

    C

    贪心??。。。
    先放2 再放1 再放所有2 再放所有1

    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <set>
    using namespace std;
    int n, cnt1, cnt2;
    int main(){
    	scanf("%d", &n);
    	for(int i = 1, x; i <= n; ++i){
    		scanf("%d", &x);
    		if(x == 1) ++cnt1; else ++cnt2;
    	}
    	if(cnt1 == 0){
    		for(int i = 1; i <= cnt2; ++i) putchar('2'), putchar(' ');
    		return 0;
    	}
    	if(cnt2 == 0){
    		for(int i = 1; i <= cnt1; ++i) putchar('1'), putchar(' ');
    		return 0; 
    	}
    	putchar('2'), putchar(' '), putchar('1'), putchar(' ');
    	for(int i = 2; i <= cnt2; ++i) putchar('2'), putchar(' ');
    	for(int i = 2; i <= cnt1; ++i) putchar('1'), putchar(' ');   
    	return 0;
    }
    

    D

    动态规划

    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <set>
    #define id(x) (x - 'a')
    using namespace std;
    const int N = 1e5 + 5;
    const int M = 255;
    const int Sig = 55;
    const int inf = 0x3f3f3f3f;
    int n, m;
    char str[N];
    int p[N][Sig], pre[Sig];
    int f[M][M][M];
    int ss[3][M], top[3];
    
    inline void ins(int type){
    	int ii, jj, kk; ii = jj = kk = 0;
    	if(type == 0) ii = top[0];
    	else if(type == 1) jj = top[1];
    	else kk = top[2]; 
    	for(int i = ii; i <= top[0]; ++i){
    		for(int j = jj; j <= top[1]; ++j){
    			for(int k = kk; k <= top[2]; ++k){
    				if(i && f[i - 1][j][k] < inf) f[i][j][k] = min(f[i][j][k], p[f[i - 1][j][k]][ss[0][i]]);
    				if(j && f[i][j - 1][k] < inf) f[i][j][k] = min(f[i][j][k], p[f[i][j - 1][k]][ss[1][j]]);
    				if(k && f[i][j][k - 1] < inf) f[i][j][k] = min(f[i][j][k], p[f[i][j][k - 1]][ss[2][k]]);
    			    //printf("%d %d %d %d
    ", i, j, k, f[i][j][k]);
    			}
    		}
    	}
    }
    
    inline void del(int type){
    	int ii, jj, kk; ii = jj = kk = 0;
    	if(type == 0) ii = top[0];
    	else if(type == 1) jj = top[1];
    	else kk = top[2]; 
    	for(int i = ii; i <= top[0]; ++i)
    		for(int j = jj; j <= top[1]; ++j)
    			for(int k = kk; k <= top[2]; ++k)
    				f[i][j][k] = inf;
    } 
    
    int main(){ 
        scanf("%d%d%s", &n, &m, str + 1);
        
        for(int i = 0; i < Sig; ++i) pre[i] = inf;
    	for(int i = n; i >= 1; --i){
    		for(int j = 0; j < Sig; ++j) p[i][j] = pre[j];
    		pre[id(str[i])] = i;
    	}  
    	for(int j = 0; j < Sig; ++j) p[0][j] = pre[j];
    	 
    	memset(f, 0x3f, sizeof(f)); f[0][0][0] = 0;
    	char opt[5], rd[5]; int x, y;
    	while(m--){
    		scanf("%s%d", opt, &x); --x;
    		if(opt[0] == '+'){
    			scanf("%s", rd); y = id(rd[0]);
    			ss[x][++top[x]] = y;
    			ins(x);
    		}
    		else {
    			del(x);
    			--top[x];
    		}
    		//printf("%d %d %d %d
    ", top[0], top[1], top[2], f[top[0]][top[1]][top[2]]);
    		if(f[top[0]][top[1]][top[2]] <= n) printf("YES
    ");
    		else printf("NO
    ");
    	}	
    	return 0;
    }
    

    E

    (题目链接)[http://codeforces.com/contest/1150/problem/E]
    跪求这道题!!!qvq有会的大佬麻烦救救孩子!!!
    感恩戴德!
    qq3338315493

  • 相关阅读:
    WINDOWS SERVER 2008 RD服务器搭建
    EXCEL技巧——SUBTOTAL函数巧妙应用
    快速理解几种常用的RAID磁盘阵列级别
    有道云笔记去除左下角广告
    git教程
    .Net导出pdf文件,C#实现pdf导出
    时间控件只显示年月
    C#中日期和时间相加的方法
    JS获取当前时间
    六大设计原则
  • 原文地址:https://www.cnblogs.com/hjmmm/p/10794309.html
Copyright © 2020-2023  润新知