• codeforces 597 div2 ABC


    codeforces 597 div2

    A:Good ol' Numbers Coloringhttp://codeforces.com/contest/1245/problem/A

    观察样例发现大概是 (gcd(a,b) eq 1)的时候是无限,试了下A了 面向样例编程

    除了cf应该不能这么意识流编程 正赛的时候这一两分钟也没那么重要

    B: Restricted RPS

    中等复杂的模拟题,但我写的时候一直wa,换了三种策略都没成,后来在广神的帮助下找到了是输出字符数组没有加结束符导致每次多样例的输出就会多很多东西,这种神奇的bug我还真是第一次遇到,记录一下。

    #include <bits/stdc++.h>
    using namespace std;
    char l[10001],out[10001];
    int main(){
        //freopen("test.in","r",stdin);
        //freopen("test.out","w",stdout);
        int t,a,b,c,n,ans;
        cin>>t;
        while(t--){
            cin>>n;
            cin>>a>>b>>c;
            cin>>l;
            for(int i=0;i<n;i++){
    			out[i]='0';
    		}
            ans=0;
            
            for(int i=0;i<n;i++){
    			if(l[i]=='R' && b>0){b--;ans++;out[i]='P';}
    			if(l[i]=='P' && c>0){c--;ans++;out[i]='S';}
    			if(l[i]=='S' && a>0){a--;ans++;out[i]='R';}
    		}
    		//cout<<out<<endl;
            for(int i=0;i<n;i++){
            	if(out[i]=='0'){
    	        	if(l[i]=='R')
    					if(a>0){a--;out[i]='R';}
    		        	else {c--;out[i]='S';}
    	        	
    	        	if(l[i]=='S')
    					if(c>0){c--;out[i]='S';}
    		        	else {b--;out[i]='P';}
    	        	
    	        	if(l[i]=='P')
    					if(b>0){b--;out[i]='P';}
    		        	else {a--;out[i]='R';}
    	        	
    			}
    		}		
            
            if(n%2==0 && ans>=(n/2)){
                cout<<"YES"<<endl;
                for(int i=0;i<n;i++)printf("%c",out[i]);
                cout<<endl;
            }
            else if(n%2==1 && ans>(n/2)){
                cout<<"YES"<<endl;
                for(int i=0;i<n;i++)printf("%c",out[i]);
                cout<<endl;
            }
            else cout<<"NO"<<endl;
        }
    return 0;
    }
            
    
    

    总结下就是算法没有问题但是wa得很靠前的时候,还是要注意下像输入输出啊预处理啊这种东西,想起来秦皇岛哪个暴力dp也是因为预处理的字符表有问题疯狂wa。

    C Constanze's Machine

    题意:

    规则1:字符串中的m会被写成nn,w写成uu

    输入为原字符串经过规则1转化而来的字符串,问原字符串有多少种可能。

    思考:

    1.若给定串中有m或w,则出错,ans=0

    2.分块

    ​ 将连续的(大于等于2个)的u/n连续子串分开,每个长度为 (l1,l2,l3...lm) 容易发现对于每个子串,

    ans[li]=ans[li-1]-ans[i-2];
    

    斐波那契啊这是!那这下就解决了

    #include<bits/stdc++.h>
    using namespace std;
    const long long mod = 1000000007;
    long long fib[201111],pre[2000011];
    char a[200011];
    int main(){
        fib[0]=1;fib[1]=1;
        for(int i=2;i<100212;i++){fib[i]=(fib[i-1]+fib[i-2])%mod;}
        cin>>a;
        long long len=strlen(a),pos=0,num=0,ans=1;
        for(int i=0;i<len;i++)if(a[i]=='w' || a[i]=='m'){cout<<'0'<<endl;return 0;}
        while(pos<len){
            if(a[pos]=='u' && a[pos+1]=='u'){
                while(a[pos]=='u' && pos<len){
                    pos++;
                    pre[num]++;
                }
                num++;
            }
            else if(a[pos]=='n' && a[pos+1]=='n'){
                while(a[pos]=='n' && pos<len){
                    pos++;
                    pre[num]++;
                }
                num++;
            }
            else pos++;
        }
        if(num==0){cout<<1<<endl;return 0;}
        for(int i=0;i<num;i++)ans = (long long) ans * fib[ pre[i]] % mod;
        cout<<ans<<endl;
    return 0;
    }
    
    
  • 相关阅读:
    MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length
    递归枚举IHTMLDocument2的所有元素
    递归创建文件和文件夹
    通过ARP协议获取MAC地址
    监控文件(夹)的改变
    ATL和MFC的C++类和HWND的映射机制
    枚举当前环境中打开的所有IE
    封装字符串的Format操作
    python decimal和fractions模块
    解决Output Designer字体问题
  • 原文地址:https://www.cnblogs.com/dpsama/p/11787988.html
Copyright © 2020-2023  润新知