• Codeforces-Round-630-Div-2


    个人博客:https://voids5.cn/2020/04/01/Codeforces-Round-630-Div-2/

    题目链接:https://codeforces.com/contest/1332

    A. Exercising Walk

    题意:在题目所给次数反复左右上下跳过程中不超过题目所给范围

    Code:

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+5;
    typedef long long ll;
    int t,a,b,c,d,x,y,x1,x2,y1,y2;
    
    int main()
    {
    	cin>>t;
    	while(t--)
    	{
    		cin>>a>>b>>c>>d;
    		cin>>x>>y>>x1>>y1>>x2>>y2;
    		if(x==x1 && x1==x2 && (a||b))
    		{
    			puts("No");
    			continue;
    		}
    		if(y==y1 && y==y2 && (c||d))
    		{
    			puts("No");
    			continue;
    		}
    		if(a>=b) a=a-b,b=0;
    		else b=b-a,a=0;
    		if(c>=d) c=c-d,d=0;
    		else d=d-c,c=0;
    		if(x-x1>=a&&x2-x>=b&&y-y1>=c&&y2-y>=d) puts("Yes");
    		else puts("No");
    	}
    
    	return 0;
      }
     
    

    B. Composite Coloring

    题意:将所给数字都染上颜色,两个数字能被染上相同数字的条件是gcd>1,且颜色最大不能超过11

    解题思路:分解质因数,不用将颜色的数量控制在最小

    Code:

    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+5;
    typedef long long ll;
    int t,n,a[N],ans[N];
    int b[N];
    
    int main()
    {
    	cin>>t;
    	while(t--)
    	{
    		memset(b,0,sizeof(b));
    		cin>>n;
    		int l=1;
    		for(int i=0;i<n;i++){
    			cin>>a[i];
    			for(int j=2;j*j<=a[i];j++){
    				if(a[i]%j==0){
    					if(b[j]) ans[i]=b[j];
    					else ans[i]=b[j]=l++;
    					break;
    				}
    			}
    		}
    		cout<<--l<<endl;
    		for(int i=0;i<n;i++){
    			cout<<ans[i]<<' ';
    		}
    		cout<<endl;
    	}
    
    	return 0;
      }
     
    

    C. K-Complete Word

    题意:给你一个字符串,要保证这个字符串本身是回文且是以k个字符为一个周期的字符串,求对字符最小改动次数使字符串满足条件

    解题思路:这个字符串是以一个周期的一半复制颠倒而成的,然后从半个周期枚举整个字符串的情况,求最小改动次数即可

    Code:

    #include<bits/stdc++.h>
    using namespace std;
    const int N=200010;
    typedef long long ll;
    int t,n,k,m;
    int a[N],c[N];
    int ans[27];
    string s;
    int main()
    {
    	cin>>t;
    	while(t--){
    		cin>>n>>k>>s;
    		int res=0;
    		for(int i=0;i<(k+1)/2;i++){
    			memset(ans,0,sizeof(ans));
    			for(int j=i;j<n;j+=k){//其他周期
    				ans[s[j]-'a']++;
    			}
    			if(k-i-1 != i){
    				for(int j=k-i-1;j<n;j+=k){ //另外半个周期加其对应的其他周期
    					ans[s[j]-'a']++;
    				}
    			}
    			int m=*max_element(ans,ans+26);//求数组中的最大值
    			int sum=accumulate(ans,ans+26,0);//计算数组的和
    			res+=sum-m;
    		}
    		cout<<res<<endl;
    	}
    
    	return 0;
      }
    
    

    D. Walk on Matrix

    题意:求最优解法和dp解法的差是k所满足的矩阵

    解题思路:使dp路径答案为0,最优路径为k(大佬的代码,先贴出来,明天再看)

    #include<bits/stdc++.h>
    using namespace std;
    const int N=200010;
    typedef long long ll;
    int t,n,k,m;
    int a[N],c[N];
    char s[N];
    int main()
    {
    	cin>>n;
    	for(int i=0;i<20 && (m+(1<<i)<3e5);i++)
    	{
    		m+=(1<<i);
    		if((n&(1<<i))==0&&k+(1<<i)<3e5){
    			k+=(1<<i);
    		}
    	}
    	cout<<2<<' '<<3<<endl;	
    	cout<<m<<' '<<k<<' '<<0<<endl;
    	cout<<n<<' '<<m<<' '<<n;
    
    	return 0;
      }
     
    
    
    七月在野,八月在宇,九月在户,十月蟋蟀入我床下
  • 相关阅读:
    oracle inside(5)
    oracle inside(4)
    WF & WCF(1)
    oracle inside(7)
    oracle inside(11)
    ArrayList使用toArray()构造数组时的问题
    在android下抓包
    为什么中国的程序员技术偏低
    [置顶] 女人与程序的对应关系!
    Java synchronized详解
  • 原文地址:https://www.cnblogs.com/voids5/p/12695012.html
Copyright © 2020-2023  润新知