2022有道小图灵信息学水平测试(三)题解
比赛地址
P
有点恶心
按顺序先填最左,然后斜着,然后向下,然后再斜着,填过不填就是
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
//#define M
//#define mo
#define N 18
int n, m, i, j, k, T;
int a[N][N];
signed main()
{
// freopen("tiaoshi.in", "r", stdin);
// freopen("tiaoshi.out", "w", stdout);
n=read();
for(i=1; i<=n; ++i) a[i][1]=++k;
for(i=n, j=1; i>=1; --i, ++j)
if(!a[i][j]) a[i][j]=++k;
for(i=1; i<=n; ++i)
if(!a[i][n]) a[i][n]=++k;
for(i=n, j=n; i>=1; --i, --j)
if(!a[i][j]) a[i][j]=++k;
for(i=1; i<=n; ++i, printf("\n"))
for(j=1; j<=n; ++j)
if(a[i][j]) printf("%5lld", a[i][j]);
else printf(" ");
return 0;
}
Q
显然从后往前维护元音数量,遇到辅音就加上当前元音数量
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
//#define M
//#define mo
#define N 1000010
int n, m, i, j, k, T;
char s[N];
signed main()
{
// freopen("tiaoshi.in", "r", stdin);
// freopen("tiaoshi.out", "w", stdout);
scanf("%s", s+1); n=strlen(s+1);
for(i=n; i>=1; --i)
{
if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u') ++k;
else m+=k;
}
printf("%lld\n", m);
return 0;
}
R
不能理解为什么答案要用复杂的二分,明明一个map就好了
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
//#define M
//#define mo
#define N 1000010
int n, m, i, j, k, T;
int a[N];
map<int, int>mp;
signed main()
{
// freopen("tiaoshi.in", "r", stdin);
// freopen("tiaoshi.out", "w", stdout);
n=read(); m=read();
for(i=1; i<=n; ++i) a[i]=read();
for(i=1; i<=m; ++i) mp[read()]=1;
for(i=1, k=0; i<=n; ++i)
if(mp[a[i]]) k=1, printf("%lld ", a[i]);
if(!k) printf("No");
return 0;
}
S
题目都告诉你是记忆化递归了,直接照着打就是了
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
//#define M
//#define mo
#define N 25
int n, m, i, j, k, T;
int f[N][N];
int w(int x, int y)
{
if(x<=0 || y<=0) return 1;
if(x>20 || y>20) return w(20, 20);
if(f[x][y]!=-1) return f[x][y];
if(x<=y) return f[x][y]=w(x, y-1)+w(x, y-2);
else return f[x][y]=w(x-1, y)+w(x-2, y);
}
signed main()
{
// freopen("tiaoshi.in", "r", stdin);
// freopen("tiaoshi.out", "w", stdout);
memset(f, -1, sizeof(f));
n=read(); m=read();
while(n!=-1 || m!=-1)
printf("%lld\n", w(n, m)), n=read(), m=read();
return 0;
}
T
**
出题人公开赛考高精
知道高精就行了,套个模板直接走人
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
//#define M
//#define mo
#define N 1000
int n, m, i, j, k, T;
int a[N], b[N];
char s[N];
signed main()
{
// freopen("tiaoshi.in", "r", stdin);
// freopen("tiaoshi.out", "w", stdout);
// k=read(); printf("%lld", k*k-k);
scanf("%s", s+1); n=strlen(s+1);
for(i=1, j=n; i<=n; ++i, --j) a[i]=s[j]-'0';
for(i=1; i<=n; ++i)
for(j=1; j<=n; ++j)
b[i+j-1]+=a[i]*a[j];
m=2*n-1;
for(i=1; i<=m; ++i)
{
if(b[i]>=10) b[i+1]+=b[i]/10, b[i]%=10;
if(b[i+1]) m=max(m, i+1);
}
while(!b[m] && m) --m;
for(i=1; i<=n; ++i) b[i]-=a[i];
for(i=1; i<=m; ++i)
if(b[i]<0) b[i]+=10, b[i+1]--;
while(!b[m] && m) --m;
// printf("%lld\n", m);
if(!m) printf("0");
else {
for(i=m; i>=1; --i) printf("%lld", b[i]);
}
return 0;
}
本文来自博客园,作者:zhangtingxi,转载请注明原文链接:https://www.cnblogs.com/zhangtingxi/p/16532595.html