A - Creating Words
题意:略
代码:
cpp
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)//不能使用scanf了
#define int long long
#define loop(n) for(int i=0;i<n;i++)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define print(c) cout<<"this "#c" is "<<c<<endl;
#define MAX INT_MAX
#define MIN INT_MIN
const int N=1010;
using namespace std;
void solve() {
string a,b;cin>>a>>b;
char c=a[0];
a[0]=b[0];
b[0]=c;
cout<<a<<' '<<b<<endl;
}
signed main() {
ios;
int n=1;
cin >> n;
while (n--)solve();
}
B - Maximum Multiple Sum
题意:略
代码:
cpp
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define loop(n) for(int i=0;i<n;i++)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define print(c) cout<<"this "#c" is "<<c<<endl;
#define MAX INT_MAX
#define MIN INT_MIN
#define N 1e6+10
using namespace std;
void solve() {
int n;cin>>n;
auto check=[&](int t){
int i=2;
for(;i<=sqrt(t);i++)
if(t%i==0)break;
if(i>=sqrt(t))return 1;
else return 0;
};
if(n<4)cout<<n<<endl;
else cout<<2<<endl;
}
signed main() {
ios;
int n=1;
cin >> n;
while (n--)solve();
}
C - Good Prefixes
题意:给数组a[n],然后定义数组的2*max=sum,则认为这个数组是好数组
我们求sum和max,然后比较即可,可以用递推优化
代码:
cpp
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define loop(n) for(int i=0;i<n;i++)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define print(c) cout<<"this "#c" is "<<c<<endl;
#define MAX INT_MAX
#define MIN INT_MIN
#define N 1e6+10
using namespace std;
void solve() {
int n; cin>>n;
int a[n]; loop(n)cin>>a[i];
int S[n],Max[n];
loop(n){
if(i==0)S[i]=a[i],Max[i]=a[i];
else S[i]=S[i-1]+a[i],Max[i]=max(Max[i-1],a[i]);
}
int count=0;
loop(n)
if(S[i]==2*Max[i])count++;
cout<<count<<endl;
}
signed main() {
ios;
int n=1;
cin >> n;
while (n--)solve();
}
D - Manhattan Circle
题意:找圆的圆心
代码:
cpp
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define loop(n) for(int i=0;i<n;i++)
#define rloop(n) for(int i=n-1;i>=0;i--)
#define print(c) cout<<"this "#c" is "<<c<<endl;
#define MAX INT_MAX
#define MIN INT_MIN
#define N 1e6+10
using namespace std;
void solve() {
int n,m;cin>>n>>m;
char a[n][m];
int line=n-1,num=0,first=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>a[i][j];
for(int i=0,count=0,k=0;i<n;i++,count=0){
for(int j=0;j<m;j++){
if(a[i][j]=='#')count++;
}
if(count==2*k+1)k++;
else if(k!=0){
line=i-1,num=count==0?1:count+2;
break;
}
//如果在最后一行,line不会赋值,则line的初始值设为n-1
}
loop(m)if(a[line][i]=='#'){
first=i;break;
}
cout<<line+1<<' '<<first+num/2+1<<endl;
}
signed main() {
ios;
int n=1;
cin >> n;
while (n--)solve();
}