每组数据为n+1个正整数单空格分割,其中第一个数为参赛厨师的人数,后面n个数为每位厨师的得分(0-100)
输出至少需要多少K的奖金
10 60 76 66 76 85 55 61 71 84 62
20
point =[int(i) for i in input().split(' ')]n =point[0]money =[1 for i in range(n+1)]for i in range(1, n+1):if i-1> 0 and i-1<=n:if point[i-1] < point[i]:money[i] =money[i-1]+1for i in range(n, 0, -1):if i+1> 0 and i+1<=n:if point[i+1] < point[i]:money[i] =max(money[i], money[i+1]+1)print(sum(money)-1)
//从左到右扫描找出左边连续最大的数 //从右到左扫描找出右边连续最大的数 //最后把每个数的左右其中最大的一个加起来即可 #include<iostream> (720)#include<vector> #include<algorithm> using namespace std; int main() { int n; cin>>n; vector<int> v(n); for(int i=0;i<n;i++) cin>>v[i]; vector<int> L(n); vector<int> R(n); int count=0; for(int i=1;i<n;i++) { if(v[i-1]<v[i]) { count++; L[i]=count; } else count=0; } count=0; for(int j=n-2;j>=0;j--) { if(v[j]>v[j+1]) { count++; R[j]=count; } else count=0; } int sum=0; for(int i=0;i<n;i++) sum+=max(L[i],R[i])+1; cout<<sum; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<int> arr(n),dp(n); for(int i=0;i<n;i++){ cin>>arr[i]; } dp[0]=1; for(int i=1;i<n;i++) dp[i]= arr[i]>arr[i-1]? dp[i-1]+1:1; for(int i=n-2;i>=0;i--){ if(arr[i]>arr[i+1]) dp[i]=max(dp[i+1]+1,dp[i]); } int sum=0; for(int i=0;i<n;i++) sum+=dp[i]; cout<<sum; return 0; }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { /** * 分糖果类型题 * 首先从左往右遍历一遍数组,我分数比你高,那我必须比你多一千块,这样便利一遍就能确保相对于左边满足了条件 * 在从右边往左边遍历一遍,我比你分数高,但是我的钱跟你一样甚至比你少,我必须要比你多1000块 * 两边遍历后就分配好了 */ public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] line1 = bf.readLine().split(" "); int n = Integer.parseInt(line1[0]); int[] score = new int[n]; int[] money = new int[n]; for (int i = 0; i < n; i++) { score[i] = Integer.parseInt(line1[i + 1]); //从左往右遍历,如果i比i-1的分数高,那我的钱一定要比你多 if (i > 0 && score[i] > score[i - 1]) { money[i] = money[i - 1] + 1; } } //在从右往左遍历 int sum = n; for (int i = n - 2; i >= 0; i--) { if (score[i] > score[i + 1] && money[i] <= money[i + 1]) { money[i] = Math.max(money[i], money[i + 1] + 1); } } for (int i = 0; i < n; i++) { sum += money[i]; } System.out.println(sum); } }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[n],b[n]; for(int i=0;i<n;i++) cin>>a[i]; b[0] = 1; for(int i=1;i<n;i++){ if(a[i]>a[i-1]) b[i] = b[i-1] + 1; else b[i] = 1; } for(int i=n-1;i>0;i--){ if(a[i]<a[i-1]) b[i-1] = max(b[i-1], b[i]+1); } int s = 0; for(int i=0;i<n;i++) s += b[i]; cout<<s<<endl; return 0; } /* 10 60 76 66 76 85 55 61 71 84 62 1 2 1 2 3 1 2 3 4 1 */
#include <stdio.h> #include <string.h> #include <vector> #include <algorithm> using namespace std; const int maxn=1000+10; vector<int> vec[110]; int vis[1010]; int a[1010]; int main() { int i,j,n; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",&a[i]); vec[a[i]].push_back(i); } int res=0; for(i=0;i<=100;i++){ if(vec[i].size()==0) continue; for(j=0;j<vec[i].size();j++){ int id=vec[i][j]; int z=0; if(id>1 && a[id-1]<a[id]) z=max(z,vis[id-1]); if(id<n && a[id+1]<a[id]) z=max(z,vis[id+1]); res+=z+1; vis[id]=z+1; } } printf("%d\n",res); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<int>num,p; while(cin>>n) { for(int i=0;i<n;i++) { int m; cin>>m; num.push_back(m); p.push_back(1); } for(int i=1;i<num.size();i++) if(num[i]>num[i-1]) p[i]=p[i-1]+1; int sum=0; for(int j=n-2;j>=0;j--) if(num[j]>num[j+1]) p[j]=max(p[j], p[j+1]+1); for(int j=0;j<n;j++) sum+=p[j]; cout<<sum<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; const int N=1e5+100; int n; int a[N]; int f[N]; int g[N]; int main(){ ios::sync_with_stdio(false); while(cin>>n){ for(int i=1;i<=n;i++) cin>>a[i]; f[1]=g[n]=1; for(int i=2;i<=n;i++) if(a[i]>a[i-1]) f[i]=f[i-1]+1; else f[i]=1; for(int i=n-1;i;i--) if(a[i]>a[i+1]) g[i]=g[i+1]+1; else g[i]=1; int ans=0; for(int i=1;i<=n;i++) ans+=max(f[i],g[i]); cout<<ans<<endl; } return 0; }
data = [int(x) for x in input().split()] data.pop(0) def count(n): return n*(n+1)//2 up,down = 0,0 old_d,cur_d = 0,0 res = 0 for i in range(1,len(data)): if data[i]>data[i-1]: cur_d = 1 elif data[i]<data[i-1]: cur_d = -1 else: cur_d = 0 if old_d==-1 and cur_d >=0 or old_d==1 and cur_d ==0: #先降再平升 或者先升在平 res+=count(up)+count(down)+max(up,down) up,down = 0,0 # if data[i]>data[i-1]: up+=1 elif data[i]<data[i-1]: down +=1 else: res+=1 old_d = cur_d res+=count(up)+count(down)+max(up,down)+1 print(res)
def score(num): res = [1 for _ in range(len(num))] for i in range(len(num)-1): if num[i]<num[i+1]: res[i+1] = res[i]+1 for j in range(len(num)-2,-1,-1): if num[j]>num[j+1]: res[j] = max(res[j],res[j+1]+1) return sum(res) if __name__=='__main__': num = list(map(int,input().split())) person = num[1:] print(score(person))