题解:P15865 【MX-X26-T1】「Cfz Round 7」feel my soul
题解:P15865 【MX-X26-T1】「Cfz Round 7」feel my soul
思路
数据范围告诉我们,对于每个
这提示了我们,肯定有一个公式,去解决每一个
我们不妨从状态比较少的,每种颜色格子左右相邻的另一种颜色的个数入手。
::::info{open}
下面所表述的内容,
| 以 |
|---|
| 我们从 |
如果
对于这种情况,如果我们把蓝换成粉,即
如果
发现了吗?如果我们把上面的
因此,一种排列可以凑成的方案数,就等于这种排列的长度。
同时,如果我们让
如果
综合一下:序列至少有
- 可以被
2 整除:2 种方案。 - 可以被
3 整除:6 种方案。 - 可以被
4 整除:4 种方案。
按这个逻辑写代码即可。
AC code
#include <iostream>
using namespace std;
int c, t;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> c >> t;
for(int i = 0; i < t; i++){
int n;
cin >> n;
int ans;
ans = 2;
if(n % 2 == 0)
ans += 2;
if(n % 3 == 0)
ans += 6;
if(n % 4 == 0)
ans += 4;
cout << ans << '\n';
}
}