Atcoder ABC155
A 题
其实不用排序,我沙壁了
#include <iostream>
#include <algorithm>
using namespace std;
int arr[3];
int main(){
for(int i = 0;i<3;i++) scanf("%d",&arr[i]);
sort(arr,arr+3);
if(arr[0] == arr[1] && arr[1] != arr[2]){
puts("Yes");
}else if(arr[0] != arr[1] && arr[1] == arr[2]){
puts("Yes");
}else{
puts("No");
}
return 0;
} B题
#include <iostream>
#include <algorithm>
using namespace std;
int N;
int arr[101010];
int main(){
cin>>N;
for(int i = 0;i<N;i++) scanf("%d",&arr[i]);
int tag = 1;
for(int i = 0;i<N;i++){
if(arr[i] % 2 == 0){
if(arr[i] %3 != 0 && arr[i]%5 !=0) {
tag = 0;
break;
}
}
}
if(tag) puts("APPROVED");
else puts("DENIED");
return 0;
} C题
使用了map自动排序的特性
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
const int maxn = 2e5+10;
int N;
struct node{
string s;
int cnt;
};
map<string,node> mp;
int main(){
cin>>N;
for(int i = 0;i<N;i++){
string s;cin>>s;
if(mp.count(s)) mp[s].cnt++;
else mp[s] = {s,1};
}
int mx = 0;
for(auto p:mp) mx = max(mx,p.second.cnt);
for(auto p:mp){
if(p.second.cnt == mx) cout<<p.first<<endl;
}
return 0;
} D题
E题
这个题就是从各位开始看,看这一个数是要付钱,还是借一位让找钱。很明显>5就借一位让找钱,<5就付钱,=5需要看左边一位是否>=5,如果>=5就借位让找钱,这样左边一位就可以通过找钱减小答案,否则就直接付钱
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
const int maxn = 2e5+10;
string s;
int main(){
cin>>s;
reverse(s.begin(),s.end());
int cnt = 0,nx = 0;
for(int i = 0;i<s.length();i++){
int cur = s[i]-'0'+nx;nx = 0;//nx为借位值
if(cur>5){
cnt += 10-cur;
nx = 1;
}else if(cur<5){
cnt += cur;
}else{
if(i+1<s.length()&& s[i+1]-'0'>=5){
cnt += 10-cur;
nx = 1;
}else{
cnt += cur;
}
}
}
if(nx) cnt += nx;
cout<<cnt<<endl;
return 0;
} F题 (难)
比赛小结
说实话这场比赛挺难的,D题调二分调到爆炸,F题死活想不出思路。不过这两题还是通过看别人的题解弄懂了,emmmmm希望是真的懂了把

京公网安备 11010502036488号