https://cometoj.com/contest/84
A
根據中國剩餘定理,x在模M= 23 X 233 x 2333下必然存在唯一解。那麼我們只需要將x從1開始不斷累加1,至多迭代M次直到找到符合條件的x即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
const int M = 4e5 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int a,b,c,ans=1;
cin >> a >> b >> c;
while(ans % 23 != a || ans % 233 != b || ans % 2333 != c) ans ++;
cout << ans;
return 0;
}
B
很明顯的可以看出 Sk的前一半是Sk-1 後一半是Sk-1完全翻轉而來
那麼自然可以想到 求Sk時用Sk-1的結果 再加上完全翻轉的部分 再加上 中間交界點的情況即可
完全翻轉部分的結果 翻轉前狀態的相反狀態+1 比如 翻轉前是 0110 翻轉後爲 1001 翻轉前 00的個數爲0 11的個數爲 1
翻轉後 00的個數爲1 11的個數爲0
01 和 10的情況同理 兩種狀態相加即可
至於中間交界點處的情況 也可以觀察出 k爲奇數時 爲01 偶數時爲 11 特判加上就好
我們可以直接想到一個遞推方程
所以代碼如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 100;
const int M = 4e5 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
int f[N][4] ,n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1;i <= n;i ++){
for(int j = 0;j < 4;j ++){
f[i][j] = (f[i - 1][j] + f[i - 1][3 ^ j]) % mod;
}
//交界點
if(i % 2){
f[i][1] = (++ f[i][1]) % mod;
}else f[i][3] = (++ f[i][3]) % mod;
}
for(int i = 0;i < 4;i ++) cout << f[n][i] << " ";
return 0;
}
當然可以想到 只用到前一狀態 可以不開存儲 直接變量存也好
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 100;
const int M = 4e5 + 100;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
int a,b,c,d,n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1;i <= n;i ++){
a = d = (a + d) % mod;
b = c = (b + c) % mod;
if(i%2) b ++;
else d ++;
}
cout << a << " " << b << " " << c << " " << d;
return 0;
}