• Educational Codeforces Round 62 (Div. 2)


    自测的时候做出了A~E
    E花的时间太多q-q

    A Detective Book

    暴力模拟

    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    using namespace std;
    const int N = 1e4 + 5;
    
    int n, ans, pre;
    
    int main(){
    	scanf("%d", &n);
    	for(int i = 1, x; i <= n; ++i){
    		scanf("%d", &x);
    		pre = max(x, pre);
    		if(i >= pre){++ans; pre = 0;}
    	}
    	printf("%d", ans);
        return 0;	
    }
    

    B Good String

    取最左边的">"和最右边的"<"与最左/右边距离的最小值

    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    using namespace std;
    const int N = 105;
    
    int n, ans, fir, las;
    char str[N];
    
    int main(){
    	int T; scanf("%d", &T);
    	while(T--){
    		scanf("%d%s", &n, str + 1);
    		fir = n, las = 1;
    		for(int i = 1; i <= n; ++i) if(str[i] == '>') {fir = i; break;}
    		for(int i = n; i >= 1; --i) if(str[i] == '<') {las = i; break;}
    		ans = min(fir - 1, n - las);
    		printf("%d
    ", ans);
    	}
        return 0;	
    }
    

    C Playlist

    按bi从大到小
    用multiset模拟1~i - 1中t最大的k个的和

    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <set>
    using namespace std;
    const int N = 3e5 + 5;
    
    int n, m;
    long long ans;
    struct Node{
    	int x, y;
    }node[N];
    inline bool rule(Node x, Node y){
    	return x.y > y.y;
    }
    multiset<int> st;
    long long stsize, len;
    
    int main(){
    	scanf("%d%d", &n, &m);
    	for(int i = 1; i <= n; ++i){
    		scanf("%d%d", &node[i].x, &node[i].y);
    	}
    	sort(node + 1, node + n + 1, rule);
    	
        for(int i = 1; i <= n; ++i){
        	if(st.size() < m){
        		st.insert(node[i].x);
        		len += node[i].x;
        	} else if((*st.begin()) < node[i].x){
        		len += node[i].x - (*st.begin());
        		st.erase(st.begin()); st.insert(node[i].x);
        	}
        	long long d = 1ll * len * node[i].y;
        	ans = max(d, ans);
        }
        printf("%lld", ans);
    	return 0;	
    }
    

    D Minimum Triangulation

    手玩一下。。。从一放射形划分

    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <set>
    using namespace std;
    const int N = 3e5 + 5;
    
    int n;
    long long ans;
    
    int main(){
    	scanf("%d", &n);
    	for(int i = 3; i <= n; ++i){
    		ans += 1ll * i * (i - 1);
    	}
    	printf("%lld", ans);
    	return 0;	
    }
    

    E Palindrome-less Arrays

    有一点麻烦的dp
    suf是每次向后跳两个
    找到第一个不为-1的数就记录
    如果没有 那么记录为后面的最后一个-1 再没有就记为零

    f[i][0]是第i个所在-1连续子串在i的位置与suf不同的种类数
    f[i][1]是第i个所在-1连续子串在i的位置与suf相同的种类数

    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <set>
    using namespace std;
    const int N = 3e5 + 5;
    const long long P = 998244353;
    
    int n, k;
    int a[N], suf[N], pre[N];
    long long f[N][2], ans = 1;
    
    int main(){
    	scanf("%d%d", &n, &k);
    	for(int i = 1; i <= n; ++i){
    		scanf("%d", &a[i]);
    		if(~a[i] && a[i] == a[i - 2]){
    			printf("0"); return 0;
    		}
    	}
    	for(int i = n - 2; i >= 1; --i){
    		if(~a[i + 2]) suf[i] = a[i + 2];
    		else suf[i] = suf[i + 2];
    	}
    	for(int i = 3; i <= n; ++i) pre[i] = a[i - 2];
    	for(int i = 1; i <= n; ++i){
    		if(~a[i]){
    			if(suf[i] == a[i]){
    				f[i][1] = 1;
    			}
    			else {
    				f[i][0] = 1;
    			}
    		}
    		else {
    			if(pre[i]){
    				if(suf[i]){
    				    if(suf[i] != a[i + 2]) f[i][1] = f[i - 2][0];
    					f[i][0] = (f[i - 2][0] * (k - 2) % P + f[i - 2][1] * (k - 1) % P) % P;	
    				}
    				else {
    					f[i][1] = 0;
    					f[i][0] = f[i - 2][0] * (k - 1) % P;
    				}
    			}
    			else {
    				if(suf[i]){
    					if(suf[i] != a[i + 2]) f[i][1] = 1;
    					f[i][0] = k - 1;
    				}
    				else {
    					f[i][1] = 0;
    					f[i][0] = k;
    				}
    			}
    		}
    	//	printf("%d %d %lld %lld
    ", pre[i], suf[i], f[i][0], f[i][1]);
    	}
    	for(int i = 1; i <= n; ++i){
    		if(suf[i] == a[i + 2]){
    			ans = ans * f[i][0] % P;
    		}
    	}
    	printf("%lld
    ", ans);
    	return 0;	
    }
    

    F Extending Set of Points

    G Double Tree

  • 相关阅读:
    mysql常用技能分享
    php生成器使用总结
    MySQL索引使用方法和性能优化
    servlet相关
    UML图
    How Tomcat Works
    字符串编码
    高效工作
    php 设计模式总结
    python之装饰器
  • 原文地址:https://www.cnblogs.com/hjmmm/p/10583238.html
Copyright © 2020-2023  润新知