XMUOJ 有的题真够恶心的。在此总结一下,同时造福后人。
厦大GPA
某位同学一共参加了4门考试,给定四门考试的总分,请问在最优情况下,4门考试绩点的和最高是多少?
分情况讨论:一门合格,两门合格,三门合格或者四门合格,只用考虑当前门合格的情况。(不然会超时)
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define N 100010
bool judge(double num, double a, double b){
return num >= a && num <= b;
}
double GPA(double num){
if(num >= 90) return 4.0;
else if(num >= 85 && num <= 89) return 3.7;
else if(num >= 81 && num <= 84) return 3.3;
else if(num >= 78 && num <= 80) return 3.0;
else if(num >= 75 && num <= 77) return 2.7;
else if(num >= 72 && num <= 74) return 2.3;
else if(num >= 68 && num <= 71) return 2.0;
else if(num >= 64 && num <= 67) return 1.7;
else if(num >= 60 && num <= 63) return 1.0;
else return 0.0;
}
#define ll long long
double ans = 0;
int n;
int a[N], id = 0;
int main(){
while(cin >> n){
ans = 0;
if(n <= 59){
puts("0.0");
continue;
}
for(int i = 60; i <= 100; i++){
if(i <= n){
ans = max(ans, GPA(i));
}
for(int j = 60; j <= 100; j++){
if(i + j <= n){
ans = max(ans, GPA(i) + GPA(j));
}
for(int k = 60; k <= 100; k++){
if(i + j + k <= n) ans = max(ans, GPA(i) + GPA(j) + GPA(k));
int h = n - i - j - k;
if(h > 0 && i + j + k + h <= n){
ans = max(ans, GPA(i) + GPA(j) + GPA(k) + GPA(h));
}
}
}
}
printf("%.1lf\n", ans);
}
return 0;
}
山谷数
直接判断有没有山峰就好了,不用管那么多。
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define N 1000010
#define ll long long
template <class T>
inline void read(T& a){
T x = 0, s = 1;
char c = getchar();
while(!isdigit(c)){ if(c == '-') s = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + (c ^ '0'); c = getchar(); }
a = x * s;
return ;
}
int y;
int main(){
while(scanf("%d", &y) != EOF){
if(y == 0){
puts("Yes");
continue;
}
int x = y;
vector <int> G;
while(x){
G.push_back(x % 10);
x /= 10;
}
bool flag = 1;
for(int i = 1; i < G.size() - 1; i++){
if(G[i] >= G[i+1] && G[i] > G[i-1])
flag = 0;
}
puts(flag ? "Yes" : "No");
}
return 0;
}