A. Rainbow Dash, Fluttershy and Chess Coloring(思维) Codeforces Round #662 (Div. 2)

原题链接:https://codeforces.com/contest/1393/problem/A

题意:给定一个正方形区域上色,要求上色的块相邻之间不能相同,也就是我们会在每回合上不同的颜色,要求上色的块邻边是边界或是上一个以上色的块。求至少要多少个回合才能把这个正方形区域完。

解题思路:很简单的一道题,首先就是要读懂题目,理解了这题目就真的太水了,我们这样想,在第一个回合,我们只能在边界的块上上色,且 要相邻上色,那么我们至少可以把边界的一半给上完,那么在下个回合,我们用不同的颜色上色自然可以把最外面的边界给上完,Ok,我们同样把最外面已经上完了的当成边界,要注意颜色相同的块是不被允许的,所以我们还是按着之前的块相邻来填,我们发现,进行完这个回合我们的区域和上个回合的是一样的,只不过长度减了2,我们每次进行这种回合都会这样子,那么我们对边长n/2即可,当然,我们还要加1,这个可以推导出来的。

AC代码:

/*
*邮箱:[email protected]
*blog:https://blog.csdn.net/hzf0701
*注:代码如有问题请私信我或在评论区留言,谢谢支持。
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<cstring>
#include<map>
#include<iterator>
#include<list>
#include<set>
#include<functional>
#include<memory.h>//低版本G++编译器不支持,若使用这种G++编译器此段应注释掉
#include<iomanip>
#include<vector>
#include<cstring>
#define scd(n) scanf("%d",&n)
#define scf(n) scanf("%f",&n)
#define scc(n) scanf("%c",&n)
#define scs(n) scanf("%s",n)
#define prd(n) printf("%d",n)
#define prf(n) printf("%f",n)
#define prc(n) printf("%c",n)
#define prs(n) printf("%s",n)
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>  pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为代码自定义代码模板***************************************//

void solve(){
	int n;
	cin>>n;
	cout<<n/2+1<<endl;
}
int main(){
	//freopen("in.txt", "r", stdin);//提交的时候要注释掉
	ios::sync_with_stdio(false);//打消iostream中输入输出缓存,节省时间。
	cin.tie(0); cout.tie(0);//可以通过tie(0)(0表示NULL)来解除cin与cout的绑定,进一步加快执行效率。
	int t;//t组测试用例
	while(cin>>t){
		while(t--){
			solve();
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/hzf0701/article/details/107872088