C题
题意:
数据范围:
思路:
时间复杂度:
#include<bits/stdc++.h>
using namespace std;
string s[110];
int main(){
int h,w;
cin>>h>>w;
for(int i=0;i<h;i++)
cin>>s[i];
for(int i=0;i<h;i++){
for(int j=0;j<w-1;j++){
if(s[i][j]=='T'&&s[i][j+1]=='T'){
s[i][j]='P';
s[i][j+1]='C';
}
}
}
for(int i=0;i<h;i++)
cout<<s[i]<<'\n';
return 0;
}
D题
题意:
数据范围:
思路:
时间复杂度:
温馨提示:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int ans;
int gcd(int a,int b){
if(b)ans+=a/b;
return b?gcd(b,a%b):a;
}
signed main(){
int a,b;
cin>>a>>b;
gcd(a,b);
cout<<ans-1;//因为在递归过程中多算了一次,所以要减掉
return 0;
}
E题
题意:
数据范围:
思路1:
思路2:
时间复杂度:
温馨提示:
#include<bits/stdc++.h>
#define int long long
using namespace std;
set<int>st;
signed main(){
int n,k;
cin>>n>>k;
st.insert(0);
for(int i=1;i<=n;i++){
int x;
cin>>x;
auto p=st.begin();
for(int j=1;j<=k;j++){
st.insert((*p)+x);
p++;
}
}
auto p=st.begin();
for(int i=1;i<=k;i++)p++;
cout<<(*p);
return 0;
}
优先队列应该可以写,但我写不来T_T