被 B 题卡了太久, D 题 OEIS 都能 O 错,无语
A
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1000005;
signed main() {
int t,n,k;
cin>>t;
while(t--) {
cin>>n>>k;
if(n>=k*k && (n-k*k)%2==0) puts("YES");
else puts("NO");
}
}
B
贪心地考虑最后一个没有匹配的公主和第一个没有匹配的国王
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1000005;
int t,n,k,tmp,a[N],b[N];
signed main() {
ios::sync_with_stdio(false);
cin>>t;
while(t--) {
cin>>n;
for(int i=1;i<=n;i++) a[i]=b[i]=0;
for(int i=1;i<=n;i++) {
cin>>k;
while(k--) {
cin>>tmp;
if(b[tmp]==0 && a[i]==0) {
a[i]=tmp;
b[tmp]=i;
}
}
}
int x=0,y=0;
for(int i=1;i<=n;i++) if(a[i]==0) x=i;
for(int i=n;i>=1;--i) if(b[i]==0) y=i;
if(x&&y) cout<<"IMPROVE"<<endl<<x<<" "<<y<<endl;
else cout<<"OPTIMAL"<<endl;
}
}
C
先把所有家伙都挪到一起,然后遍历整个地图即可
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1000005;
int n,m,k;
signed main() {
cin>>n>>m>>k;
cout<<(n-1)+(m-1)+(n-1)+n*(m-1)<<endl;
for(int i=1;i<n;i++) cout<<"U";
for(int i=1;i<m;i++) cout<<"L";
for(int i=1;i<=n;i++) {
for(int j=1;j<m;j++) if(i&1) cout<<"R"; else cout<<"L";
if(i<n) cout<<"D";
}
}
E
OEIS 即可
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1000005;
const int mod = 998244353;
int a[N],s[N];
int n;
int qpow(int p,int q) {
return (q&1?p:1)*(q?qpow(p*p%mod,q/2):1)%mod;
}
signed main() {
cin>>n;
a[1]=10;
a[2]=180;
a[3]=2610;
for(int i=4;i<=n;i++) {
a[i]=20*a[i-1]%mod-100*a[i-2]%mod;
a[i]=(a[i]+mod)%mod;
}
for(int i=n;i>=1;--i) cout<<(a[i])%mod<<" ";
}