# A.Sum of Odd Integers

k个奇数的最小和即:1,3,5,…

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,t,m;
void solve(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
if(1ll*m*m>n){
printf("NO\n");
continue;
}
if((n&1)&&(m&1)) printf("YES\n");
else if(!(n&1)&&!(m&1)) printf("YES\n");
else printf("NO\n");
}
}
int main(void)
{
solve();
return 0;
}


# B.Princesses and Princes

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5+5;
int t,n,k,num,ans1,ans2;
bool vis1[MAX],vis2[MAX],flag;
void solve(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;++i) vis1[i]=vis2[i]=false;
ans1=ans2=0;
for(int i=1;i<=n;++i){
flag=false;
scanf("%d",&k);
while(k--){
scanf("%d",&num);
if(!vis2[num]&&!flag)
vis2[num]=flag=vis1[i]=true;
}
}
for(int i=1;i<=n;++i){
if(!vis1[i]) ans1=i;
if(!vis2[i]) ans2=i;
}
if(ans1){
printf("IMPROVE\n");
printf("%d %d\n",ans1,ans2);
}
else printf("OPTIMAL\n");
}
}
int main(void)
{
solve();
return 0;
}


# C.Game with Chips

nm内即可.

n*m

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,k,num;
char op='R';
void solve(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=k;++i) scanf("%d%d",&num,&num);
for(int i=1;i<=k;++i) scanf("%d%d",&num,&num);
printf("%d\n",n+m+n*m-1);
for(int i=1;i<=m;++i) printf("L");
for(int i=1;i<=n;++i) printf("U");
for(int i=1;i<=n;++i){
for(int j=1;j<m;++j) printf("%c",op);
if(i!=n)printf("D");
op=op=='R'?'L':'R';
}
}
int main(void)
{
solve();
return 0;
}


# D.Infinite Path

$p^k$[1],$p^k$[2],$p^k$[3],…,$p^k$[n].

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e5+5;
const int INF = 0x3f3f3f3f;
int t,n,p[MAX],c[MAX],tot,ans;
vector<int> list1[MAX];
bool vis[MAX];
void dfs(int now){
list1[tot].push_back(now);
vis[now]=true;
if(!vis[p[now]]) dfs(p[now]);
}
void solve(){
scanf("%d",&t);
while(t--){
scanf("%d",&n); ans=INF;
for(int i=0;i<=n;++i) vis[i]=false,tot=0;
for(int i=1;i<=n;++i) scanf("%d",&p[i]);
for(int i=1;i<=n;++i) scanf("%d",&c[i]);
for(int i=1;i<=n;++i)
if(!vis[p[i]]){ list1[tot].clear();dfs(p[i]);++tot; }
for(int i=0;i<tot;++i){
int len = list1[i].size();
for(int j=1;j<=len;++j){
if(len%j==0){
bool flag1 = false;
int cnt = len/j;
for(int s=0;s<j;++s){
bool flag=true;
int index=s,last=-1;
for(int k=0;k<cnt;++k,(index+=j)%=len){
if(last==-1) last = c[list1[i][index]];
else if(last!=c[list1[i][index]]){ flag=false;break; }
}
if(flag){ ans=min(ans,j);flag1=true;break; }
}
if(flag1) break;
}
}
}
printf("%d\n",ans);
}
}
int main(void)
{
solve();
return 0;
}


# E. Count The Blocks

1.假如该块在数字的边界位置,i代表块的长度.

2.假如该块在数字的中间位置

10代表该块有10种情况.9
9代表该块旁边两位各有9种情况相乘.
n-i-1代表该块可以放在中间的n-i-1个位置,

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5+5;
const ll mod = 998244353;
ll quick(ll a,ll n){
ll ans=1;
while(n>0){
if(n&1) ans=ans*a%mod;
n>>=1;
a=a*a%mod;
}
return ans;
}
void solve() {
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++) {
if(i==n) { printf("10\n");continue; }
ll ans=0;
(ans+=1ll*10*9*2*quick(10,n-i-1))%=mod;
(ans+=1ll*10*9*9*(n-i-1)*quick(10,n-i-2))%=mod;
printf("%lld ",ans);
}
}
int main() {
solve();
return 0;
}


©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试