• AtCoder Beginner Contest 264(A-D)


    题单戳这里

    A - “atcoder”.substr()

    题意: 输出atcoder指定位置的字母

    void solve()
    {
    	string s="atcoder";
    	int n,m;
    	cin>>n>>m;
    	for(int i=n-1;i<=m-1;i++)
    		cout<<s[i];
    	return;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    B - Nice Grid

    题意: 给定一个图形输出对应方格的颜色
    图像如下图像如图

    模拟题解:

    void solve()
    {
    	int r,c;
    	cin>>r>>c;
    	if((r==2||r==14)&&c!=1&&c!=15)cout<<"white"<<endl;
    	else if((r==3||r==13)&&(c==2||c==14))cout<<"white"<<endl;
    	else if((r==4||r==12)&&c!=1&c!=3&&c!=13&&c!=15)cout<<"white"<<endl;
    	else if((r==5||r==11)&&(c==2||c==4||c==12||c==14))cout<<"white"<<endl;
    	else if((r==6||r==10)&&c!=1&&c!=3&&c!=5&&c!=11&&c!=13&&c!=15)cout<<"white"<<endl;
    	else if((r==7||r==9)&&(c==2||c==4||c==6||c==10||c==12||c==14))cout<<"white"<<endl;
    	else if(r==8&&(c==2||c==4||c==6||c==8||c==10||c==12||c==14))cout<<"white"<<endl;
    	else cout<<"black"<<endl;
    	return;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    利用对称奇偶性的题解:

    puts(min({R, 16 - R, C, 16 - C}) % 2 ? "black" : "white");
    
    • 1

    C - Matrix Reducing

    题意: 能否将第一个矩阵通过删行或者列转化成第一个矩阵?

    一行的数字只要是没有删,就一定在一行内;
    同理,一列的数字只要没有删除,就一定在一列内
    那么可以直接通过行列比较找是否满足所有在矩阵2中出现过的数字都能够在矩阵1中出现

    void solve()
    {
    	int n1,m1;
    	cin>>n1>>m1;
    	for(int i=1;i<=n1;i++){
    		for(int j=1;j<=m1;j++)
    			cin>>A[i][j];
    	}
    	int n2,m2;
    	cin>>n2>>m2;
    	for(int i=1;i<=n2;i++){
    		for(int j=1;j<=m2;j++)
    			cin>>B[i][j];
    	}
    	int x=1,y=1;//比较同一行的数字是否都能够满足
    	for(int i=1;i<=n1;i++){
    		for(int j=1;j<=m1;j++){
    			if(A[i][j]==B[x][y])
    				y++;
    		}
    		if(y>m2)
    			x++;
    		y=1;
    	}
    	if(x<=n2){
    		puts("No");
    		return;
    	}
    	x=1,y=1;//比较同一列的数字是否都能够满足
    	for(int i=1;i<=m1;i++){
    		for(int j=1;j<=n1;j++){
    			if(A[j][i]==B[x][y])
    				x++;
    		}
    		if(x>n2)
    			y++;
    		x=1;
    	}
    	if(y<=m2){
    		puts("No");
    		return;
    	}
    	puts("Yes");
    	return;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45

    D- “redocta”.swap(i,i+1)

    题意: 输入任意一个将"atcoder"打乱后的字符串,每次只能够将相邻的两个字母进行交换,那么最少交换多少次能够将字符串还原?

    设想当原来在前面的字符出现在后面时,一定要将它交换到前面来,那么出现在它前面的字符都会向后移动一格,那么也就离其原来的位置近了一格。

    那么可以直接按照"atcoder"的顺序进行依次比较,只要是不在原位上的字符就应该找到它并将它交换到前面来,这样一定是最小的。

    void solve()
    {
    	string s="atcoder";
    	string c;
    	cin>>c;
    	int ans=0;
    	for(int i=0;i<7;i++){
    		int pos=i;
    		while(c[pos]!=s[i])pos++;
    		ans+=(pos-i);
    		for(int j=pos;j>i;j--)swap(c[j],c[j-1]);
    	}
    	cout<<ans<<endl;
    	return;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    总结

    模拟可以有很多种写法,要学会利用好图形的变化关系,找到写的最快的写法。

  • 相关阅读:
    Keras深度学习实战(38)——图像字幕生成
    深入理解JVM类加载机制与双亲委派模型
    盘点国内主流数字孪生厂商!你了解几家?
    人文社科类夏校推荐合集
    python 定时器
    Error: 0x800701bc WSL 2 ?????????????????? https://aka.ms/wsl2kernel
    一起瓜分20万奖金!第三届火焰杯软件测试大赛开始公开选拔!
    Bash脚本自学 - 变量和位置自变量
    浅谈 synchronized 锁机制原理 与 Lock 锁机制
    spring5.0 源码解析 createBeanInstance 09
  • 原文地址:https://blog.csdn.net/m0_53735019/article/details/126350500