比赛地址 :
牛客小白月赛78
A.几何糕手
题目链接 :
几何糕手
题面 :
思路 :
数学模拟题;
最大面积就是在a与b成一条直线的情况下;
so : 输出pi * (a+b) * (a+b)即可
注意 : 注意精度!!!
代码 :
#include<iostream>
#include<algorithm>
using namespace std;
const double pi = 3.141592653589793238462643383279502884197169399;
int main(){
int a,b;
cin>>a>>b;
double ans = 1.0 * pi * ((a+b)*(a+b)) ;
printf("%.10f",ans);
return 0;
}
B.国际裁判带师
原题链接 :
国际裁判带师
题面 :
思路 :
数据量小,模拟即可;
具体模拟过程请看代码 :
代码 :
#include<iostream>
#include<algorithm>
#include<cstring>
typedef long long LL;
using namespace std;
int cnt(string t){
int cnt = 0;
for(char c : t) if(c=='0') cnt ++;
return cnt;
}
string tran(string &t,char c){
if(c=='a'){
if(t[1]-'0' >=0 && t[1]-'0'<= 8) t[1]++;
else{
t[0]++;
t[1] = '0';
}
}else {
if(t[3]=='9'){
t[2]++;
t[3]='0';
}else t[3]++;
}
return t;
}
int main(){
string s ;
LL ans;
cin>>s;
string t = "0000";
for(char c : s){
tran(t,c);
ans += cnt(t);
}
cout << ans << endl;
}
C.第K小表示数
链接 :
第K小表示数
思路 :
用一个set集合来实现去重和排序,然后模拟加入的过程;
代码 :
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
ll k, a, b, l;
cin>>k>>a>>b;
set<ll> s;
s.insert(a);
s.insert(b);
while (k--) {
l = *s.begin();
s.erase(s.begin());
s.insert(l+a);
s.insert(l+b);
}
cout<<(l);
return 0;
}
// 2 3 4 5