2020.10.18补题
E - High School: Become Human
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.
One of the popular pranks on Vasya is to force him to compare $$$x^y$$$ with $$$y^x$$$. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.
Please help Vasya! Write a fast program to compare $$$x^y$$$ with $$$y^x$$$ for Vasya, maybe then other androids will respect him.
#include<bits/stdc++.h> #define ll long long const int maxn = 1e5 + 5; using namespace std; int main() { long long a,b; cin>>a>>b; long double x=b*log(a); //记录n的m次方 long double y=a*log(b); //记录m的n次方 if(x>y) cout<<">"<<endl; else if(x==y) cout<<"="<<endl; else cout<<"<"<<endl; return 0; }
字符串处理:
对于字符串操作的插入删除可以参考:https://blog.csdn.net/wang1997hi/article/details/78364755
对于字符串操作的查找可以参照:https://www.cnblogs.com/komean/p/11109555.html
F - Three displays
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $$$n$$$ displays placed along a road, and the $$$i$$$-th of them can display a text with font size $$$s_i$$$ only. Maria Stepanovna wants to rent such three displays with indices $$$i < j < k$$$ that the font size increases if you move along the road in a particular direction. Namely, the condition $$$s_i < s_j < s_k$$$ should be held.
The rent cost is for the $$$i$$$-th display is $$$c_i$$$. Please determine the smallest cost Maria Stepanovna should pay.
题意:根据广告牌的递增位置选择租金最少的三块广告牌。
思路:从第二个开始向后枚举找到最小的三个和。这里借鉴网上的代码,对于inf的初始值有些不明白。
#include<bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f using namespace std; const int maxx=3e3+100; int a[maxx],b[maxx]; int n; int main() { set<int> s; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&b[i]); int _max3=inf; for(int i=1;i<=n;i++) { int _max1=inf,_max2=inf; for(int j=1;j<i;j++) if(a[j]<a[i]) _max1=min(_max1,b[j]); //前面最小的 for(int j=i+1;j<=n;j++) if(a[j]>a[i]) _max2=min(_max2,b[j]); //后面最小的 _max3=min(_max3,_max1+_max2+b[i]); //寻找最小的和 } if(_max3==inf) puts("-1"); else printf("%d\n",_max3); }
浙公网安备 33010602011771号