C - Trains
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
/*
*/
int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
int main()
{
speed_up;
int a,b;
cin>>a>>b;
ll c=1ll*a/gcd(a,b)*b;
int c1=c/a-1;//去dasha的次数,-1是减去最后那个点
int c2=c/b-1;//去masha的次数
if(c1<c2)c1++;//最后去dasha
else if(c1>c2)c2++;//最后去masha
if(c1>c2)cout<<"Dasha"<<endl;
else if(c1<c2)cout<<"Masha"<<endl;
else cout<<"Equal"<<endl;
}
B - Keyboard
样例都过但在测试点26wa了 找不到bug
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
speed_up;
int n,m,x;
cin>>n>>m>>x;
char a[n][m];//存键盘
map<char,int>mp;//存键盘中的字母(都是小写
int f=0;
vector<int>xx;//存每个S的位置坐标
vector<int>yy;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
cin>>a[i][j];
if(a[i][j]!='S')
{
mp[a[i][j]]=1;
}
if(a[i][j]=='S')
{
xx.push_back(i);
yy.push_back(j);
f=1;//有S
}
}
}
int t;
cin>>t;
string s;
cin>>s;
int ff=0;
for(int i=0; i<t; i++)
{
ff=0;
if(s[i]>='A'&&s[i]<='Z')//1、判断能不能大写
{
if(!f||!mp[s[i]-'A'+'a'])
{
cout<<"-1"<<endl;
ff=1;
break;
}
}
if((s[i]>='a'&&s[i]<='z')&&!mp[s[i]])//2、判断键盘中有没有这个字符
{
cout<<"-1"<<endl;
ff=1;
break;
}
}
if(!ff)
{
double cha[27];
for(int i=0; i<=27; i++)
cha[i]=35;
for(int k=0; k<xx.size(); k++)
//遍历每个S坐标,将它和每个字符的坐标最大差值存起来,每次遍历都更新一次,存那个距离S最近的
{
for(int ii=1; ii<=n; ii++)
{
for(int jj=1; jj<=m; jj++)
{
//cout<<a[ii][jj]<<endl;
if(a[ii][jj]!='S')
{
double maxx=(ii-xx[k])*(ii-xx[k])+(jj-yy[k])*(jj-yy[k]);
maxx=sqrt(maxx);
//int maxx=max(abs(ii-xx[k]),abs(jj-yy[k]));//刚开始理解错了欧几里得距离
//cout<<maxx<<endl;
if(cha[a[ii][jj]-'a']>maxx)//更新字符与S的最短距离
{
cha[a[ii][jj]-'a']=maxx;
//cout<<a[ii][jj]<<"*"<<endl;
}
}
}
}
}
for(int i=0; i<=27; i++)
{
char t=i+'a';
//cout<<cha[i]<<t<<endl;
}
int cnt=0;
for(int i=0; i<t; i++)
{
if(s[i]>='A'&&s[i]<='Z')
{
s[i]=s[i]-'A'+'a';//先把这个字符转换为小写
if(cha[s[i]-'a']>x)
{
cnt++;
//cout<<s[i]<<endl;
}
}
}
cout<<cnt<<endl;
}
}