A-Probably English
共有\(n\)个单词,如果出现过and, not, that, the,you其中一个单词至少一次,输出\(Yes\),否则,输出\(No\)。(输入的单词均为小写)
按题意模拟即可:
#include<iostream>
using namespace std;
#define ll long long
inline ll read();
ll n;bool flag;
string s;
string s1={'a','n','d'},s2={'n','o','t'},s3={'t','h','a','t'},s4={'y','o','u'},s5={'t','h','e'};
int main()
{
n=read();
for(int i=1;i<=n;i++){
cin>>s;
(s==s1||s==s2||s==s3||s==s4||s==s5) ? (flag=true):flag=flag;
}
flag? cout<<"Yes" : cout<<"No";
return 0;
}
ll read(){ll w=1,x=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0' && ch<='9'){x=x*10+(ch-'0');ch=getchar();}return x*w;}
B - Bombs
一个\(R\)行\(C\)列的矩阵,由"#""."和数字构成。其中,数字\(c\)是炸弹,可以把其周围曼哈顿距离不大于\(c\)的"#"变成"."。输出所有炸弹爆照后的矩阵。
考虑到\(1≤R,C≤20\),,所以每扫到一个数字直接暴力枚举矩阵中每一个元素即可。最多运算次数:\(20^{4}\)。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define ll long long
inline ll read();
ll ju(ll x){
return x>0 ? (x):(-1*x);
}
ll n,m;
int a[50][50];
void work(ll x,ll y,ll q)
{
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==-2){
if(ju(x-i) + ju(y-j) <=q){
a[i][j]=-1;
}
}
}
}
}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char ch;cin>>ch;
if(ch=='.'){
a[i][j]=-1;
}
else if(ch=='#'){
a[i][j]=-2;
}
else if(ch>='0' && ch <='9'){
a[i][j]=ch-'0';
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]>0){
work(i,j,a[i][j]);
a[i][j]=-1;
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==-1){
cout<<'.';
}
if(a[i][j]==-2){
cout<<'#';
}
}
cout<<endl;
}
return 0;
}
ll read(){ll w=1,x=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0' && ch<='9'){x=x*10+(ch-'0');ch=getchar();}return x*w;}
C - Socks
共有\(N\)个袜子,每个袜子的颜色是\(A_{i}\),求最多能配成多少对颜色相同的袜子
开一个map数组记录一下当前这个颜色的袜子是单数还是复数,单数就ans++。
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
#define ll long long
inline ll read();
map<ll,bool> vis;
ll n;ll ans=0;
int main()
{
ll n=read();
for(int i=1;i<=n;i++){
ll a=read();
if(vis[a]){
ans++;vis[a]=false;
}
else{
vis[a]=true;
}
}
cout<<ans;
return 0;
}
ll read(){ll w=1,x=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0' && ch<='9'){x=x*10+(ch-'0');ch=getchar();}return x*w;}
标签:ch,int,题解,ll,long,read,include,ABC295
From: https://www.cnblogs.com/mikufun4405/p/17256213.html