https://atcoder.jp/contests/abc211/tasks/abc211_a
A - Blood Pressure Editorial
水题,给你a,b,求c。
公式:c=((a-b)/3 )+b;
如果c是整数就输出整数,如果c不是整数就保留7位小数
代码:
#include<bits/stdc++.h>
#define ll long long
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define hh 0x3f3f3f3f
const int maxn=1e5+5;
using namespace std;
inline int read()
{
ll s=0,f=1;
char c=getchar();
while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){s=(s<<3)+(s<<1)+c-'0';c=getchar();}
return s*f;
}
void solve()
{
double a,b,c;
int tp;
scanf("%lf%lf",&a,&b);
c=(a-b)/3+b;
tp=c+0.99;
if(c==tp)
{
printf("%d",tp);
}
else
{
printf("%.7lf",c);
}
}
int main()
{
ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int t=1;
while(t--)solve();
return 0;
}
https://atcoder.jp/contests/abc211/tasks/abc211_b
B - Cycle Hit
水题。
题意:给你四组字符串,保证这四组只含H,2B,3B,HR。如果出现了H,2B,3B,HR那么就输出Yes否则就输出No。
思路:用map记录出现的字符串,如果出现相同的字符串那么就输出No,反之就输出Yes。
代码:
#include<bits/stdc++.h>
#define ll long long
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define hh 0x3f3f3f3f
const int maxn=1e5+5;
using namespace std;
inline int read()
{
ll s=0,f=1;
char c=getchar();
while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){s=(s<<3)+(s<<1)+c-'0';c=getchar();}
return s*f;
}
map<string,int>q;
char s[10];
// H 2B 3B HR
void solve()
{
int n=4;
for(int i=1;i<=n;i++)
{
cin>>s;
if(q[s]==1)
{
cout<<"No";
return ;
}
else q[s]=1;
}
cout<<"Yes";
}
int main()
{
ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int t=1;
while(t--)solve();
return 0;
}
https://atcoder.jp/contests/abc211/tasks/abc211_c
C - chokudai
题意:给你一串字符串,按照字符串的位置顺序问你有多少种可能可以拼接成chokudai这个字符串
比如:给你chchokudai
我们会有三种拼接的方式:
chchokudai
chchokudai
chchokudai
思路O(n):迭代、递推。
首先我们遇到 c 时就可以让带有 c 的容器+1;
遇到 h 时,我们就可以算出 h 之前一共有多少个 c,我们让 ch 容器加上 h 之前的 c 出现的次数;
遇到 o 时,我们就可以算出 o 之前 一共有多少个 ch ,我们让 cho 容器加上 o 之前 ch 出现的次数;
遇到 k 时,我们就可以算出 k 之前一共有多少个 cho,我们就让 chok 容器加上 k 之前出现 cho 出现的次数........
遇到 a 时,我们就可以算出 a 之前一共有多少个 chchokud ,我们就让 chchokuda 容器加上 a 之前出现 chchokud 的次数。
遇到 i 时,我们就可以算出 i 之前一共有多少个 chchokuda,我们就让 chchokudai 容器加上i之前出现 chchokuda 的次数。
最后输出 chchokudai 容器的个数即可。
代码:
#include<bits/stdc++.h>
#define ll long long
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define hh 0x3f3f3f3f
const int maxn=1e5+5;
using namespace std;
inline int read()
{
ll s=0,f=1;
char c=getchar();
while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){s=(s<<3)+(s<<1)+c-'0';c=getchar();}
return s*f;
}
map<string,ll>q;
ll mod=1e9+7,ans=0;
char s[maxn];
void solve()
{
cin>>s+1;
int len=strlen(s+1);
for(int i=1;i<=len;i++)
{
if(s[i]=='c')q["c"]++;
else if(s[i]=='h')
q["ch"]=(q["ch"]+q["c"])%mod;
else if(s[i]=='o')
q["cho"]=(q["cho"]+q["ch"])%mod;
else if(s[i]=='k')
q["chok"]=(q["chok"]+q["cho"])%mod;
else if(s[i]=='u')
q["choku"]=(q["choku"]+q["chok"])%mod;
else if(s[i]=='d')
q["chokud"]=(q["chokud"]+q["choku"])%mod;
else if(s[i]=='a')
q["chokuda"]=(q["chokuda"]+q["chokud"])%mod;
else if(s[i]=='i')
q["chokudai"]=(q["chokudai"]+q["chokuda"])%mod;
}
cout<<q["chokudai"];
}
int main()
{
ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int t=1;
while(t--)solve();
return 0;
}