2022有道小图灵信息学水平测试(二)题解
比赛地址
K
看看有多少个数小于等于 即可
#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 1010
int n, m, i, j, k, T;
int a[N];
signed main()
{
// freopen("tiaoshi.in", "r", stdin);
// freopen("tiaoshi.out", "w", stdout);
n=read(); k=read();
for(i=1; i<=n; ++i) a[i]=read();
for(i=1; i<=n; ++i) if(a[i]<=a[k]) ++j;
printf("%d", j);
return 0;
}
L
显然,0全丢前面,1全丢后面
#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 100010
int n, m, i, j, k, T;
char a[N];
signed main()
{
// freopen("tiaoshi.in", "r", stdin);
// freopen("tiaoshi.out", "w", stdout);
n=read();
scanf("%s", a+1);
// for(i=1; <=n; ++i) a[i]=read();
sort(a+1, a+n+1);
for(i=1; i<=n; ++i) printf("%c", a[i]);
return 0;
}
M
用个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
int n, m, i, j, k, T;
signed main()
{
// freopen("tiaoshi.in", "r", stdin);
// freopen("tiaoshi.out", "w", stdout);
T=read();
while(T--)
{
map<string, int>mp;
string s, c;
n=read();
for(i=1; i<=n; ++i)
{
cin>>s; mp[s]=1;
c+=s[0];
}
printf(mp[c] ? "yes\n" : "no\n");
}
return 0;
}
N
DP,设 代表前 枚硬币里最后一枚是反面/正面朝上的方案数
#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 40
int n, m, i, j, k, T;
int dp[N][2];
signed main()
{
// freopen("tiaoshi.in", "r", stdin);
// freopen("tiaoshi.out", "w", stdout);
n=read();
dp[1][1]=dp[1][0]=1;
for(i=2; i<=n; ++i)
{
dp[i][1]=dp[i-1][1]+dp[i-1][0];
dp[i][0]=dp[i-1][1];
}
printf("%lld", dp[n][0]+dp[n][1]);
return 0;
}
O
按题意所说排序即可
#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 100010
struct node
{
int x, y, a, b, c;
string s;
}a[N];
int n, m, i, j, k, T;
bool cmp(node x, node y)
{
if(x.a==y.a) {
if(x.b==y.b) {
if(x.c==y.c) return x.s<y.s;
return x.c<y.c;
}
return x.b<y.b;
}
return x.a<y.a;
}
signed main()
{
// freopen("tiaoshi.in", "r", stdin);
// freopen("tiaoshi.out", "w", stdout);
n=read();
for(i=1; i<=n; ++i)
{
m=read();
for(j=1; j<=m; ++j)
{
a[++k].x=i; a[k].y=j;
cin>>a[k].s;
a[k].a=read(); a[k].b=read(); a[k].c=read();
}
}
sort(a+1, a+k+1, cmp);
for(i=1; i<=k; ++i)
cout<<a[i].s, printf(" %d %d\n", a[i].x, a[i].y);
return 0;
}
本文来自博客园,作者:zhangtingxi,转载请注明原文链接:https://www.cnblogs.com/zhangtingxi/p/16532563.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!