【题解】CF1950B Upscaling

CF1950B Upscaling题解

题意

给予你一个正整数 \(n\),构造一个如图的字符矩阵。
如图

思路

注意数据 \(1\le n \le 20\),可以发现数据很小,于是我们可以暴力模拟。

我们可以将两列看为一列,两行看为一行。

然而我们可以发现缩成的一行的 \(i\) 等于被缩的两行的 \({i\div2}\) 的向上取整。

而缩成的一行的 \(i\) 如果是奇数,则证明被缩的两行在一二或五六行。

列与行是类似的。

缩成的一列的 \(i\) 等于被缩的两列的 \({i\div2}\) 的向上取整。

而缩成的一列的 \(i\) 如果是奇数,则证明被缩的两列在一二或五六列。

再根据它的行和列判断它是井号还是点。

代码

#include<bits/stdc++.h>
using namespace std;
int t,n;
int main(){
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=2*n;i++){
			for(int j=1;j<=2*n;j++){
				if(int(ceil(1.0*i/2))%2==1){//12,56行 
					if(int(ceil(j*1.0/2))%2==1){//12,56列 
						cout<<"#";
					}else{//34,78列 
						cout<<".";
					}
				}else{//34,78行 
					if((int)(ceil(j*1.0/2))%2==1){//12,56列 
						cout<<".";
					}else{//34,78列 
						cout<<"#";
					}
				}
			}
			cout<<"\n";
		}
	}
	return 0;
}
posted @ 2024-04-06 17:28  Kcjhfqr  阅读(59)  评论(0)    收藏  举报
.poem-wrap { position: relative; width: 1000px; max-width: 80%; border: 2px solid #797979; border-top: none; text-align: center; margin: 40px auto; } .poem-left { left: 0; } .poem-right { right: 0; } .poem-border { position: absolute; height: 2px; width: 27%; background-color: #797979; } .poem-wrap p { width: 70%; margin: auto; line-height: 30px; color: #797979; } .poem-wrap h1 { position: relative; margin-top: -20px; display: inline-block; letter-spacing: 4px; color: #797979; font-size: 2em; margin-bottom: 20px; } #poem_sentence { font-size: 25px; } #poem_info { font-size: 15px; margin: 15px auto; }