A - Slot
Problem Statement
You are playing the slots.
The result of a spin is represented by three uppercase English letters C1, C2, and C3. It is considered a win when all of them are the same letter.
Determine whether it is a win.
Constraints
Ci is an uppercase English letter.
Sample Input
SSS
Sample Output
Won
All of them are the same letter, so it is a win.
解题思路: 看字符串中的字符是否相等。
#include<iostream>
#include<string>
using namespace std;
int main(){
string a;
cin>>a;
for(int i=1;i<a.size();i++){
if(a[i]!=a[0]){
cout<<"Lost"<<endl;
return 0;
}
}
cout<<"Won"<<endl;
return 0;
}
B - Alcoholic
Problem Statement
Takahashi had N glasses of liquor.
The amount and alcohol percentage of the i-th liquor were Vi milliliters and Pi percent by volume, respectively.
Takahashi gets drunk when his alcohol intake exceeds X milliliters.
Which of the N liquors was he drinking when he gets drunk? If he was not drunk even after drinking all the liquors, print -1 instead.
Constraints
All values in input are integers.
1≤N≤10
30≤X≤1e6
1≤Vi≤1e3
0≤Pi≤100
Sample Input
2 15
200 5
350 3
Sample Output
2
解题思路:这题刚开始我考虑到了小数,于是直接上double,但是总有7个点过不去,怎么都没想到是精度问题,后来改成float,变成了3个点,最后直接用int就过了……有些无语。
#include<iostream>
typedef long long ll;
int x;
int n;
int v[1005],p[1005];
int c[1005],sum=0;
using namespace std;
int main(){
cin>>n>>x;
for(int i=0;i<n;i++){
cin>>v[i]>>p[i];
c[i]=v[i]*p[i];
}
for(int i=0;i<n;i++){
sum+=c[i];
if(sum>x*100){
cout<<i+1<<endl;
return 0;
}
}
cout<<"-1"<<endl;
return 0;
}
C - Mandarin Orange
Problem Statement
There are N dishes arranged in a row in front of Takahashi. The i-th dish from the left has Ai oranges on it.
Takahashi will choose a triple of integers (l,r,x) satisfying all of the following conditions:
1≤l≤r≤N;
1≤x;
for every integer i between l and r (inclusive), x≤Ai.
He will then pick up and eat x oranges from each of the l-th through r-th dishes from the left.
At most how many oranges can he eat by choosing the triple (l,r,x) to maximize this number?
Constraints
All values in input are integers.
1≤N≤1e4
1≤Ai≤1e5
Sample Input
6
2 4 4 9 4 9
Sample Output
20
By choosing (l,r,x)=(2,6,4), he can eat 20 oranges.
解题思路: 双循环嵌套,找出最小的,在算出这个范围中的ans,每次都记录最小的ans。
#include<iostream>
using namespace std;
int a[10010];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
int ans=0;
for(int i=0;i<n;i++){
int x=a[i];
for(int j=i;j<n;j++){
x=min(x,a[j]);
ans=max(ans,x*(j-i+1));
}
}
cout << ans;
}