Kick Start Round D 2020(前两题)
Posted tws-yifei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kick Start Round D 2020(前两题)相关的知识,希望对你有一定的参考价值。
https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ff08?scoreboard_type=China
A.当前数比前面所有和后面一个都大的时候,算做破纪录一次。遍历一遍。
#include <bits/stdc++.h> using namespace std; vector<int> visiter(1000005,0); int main() { int T,N; int currmax=-1; int res=0; cin>>T; for(int i=0;i<T;i++){ currmax=-1; res=0; cin>>N; for(int j=0;j<N;j++){ cin>>visiter[j]; } cout<<"Case #"<<i+1<<": "; if(N==1){ cout<<1; }else{ for(int j=0;j<N-1;j++){ if(visiter[j]>currmax && visiter[j]>visiter[j+1]){ res++; } currmax=max(currmax,visiter[j]); } if(visiter[N-1]>currmax) res++; cout<<res; } cout<<endl; } return 0; }
B.将多音高的音乐转换成只有4个音高的音乐,问最小破坏规则的次数。动态规划
#include <bits/stdc++.h> using namespace std; int notes[10005]; int dp[10005][4]; int main() { int T,K; dp[0][0]=0; dp[0][1]=0; dp[0][2]=0; dp[0][3]=0; int res=0; cin>>T; for(int i=0;i<T;i++){ cin>>K; for(int j=0;j<K;j++){ cin>>notes[j]; } cout<<"Case #"<<i+1<<": "; for(int j=1;j<K;j++){ if(notes[j]>notes[j-1]){ dp[j][0]=min(min(dp[j-1][0],dp[j-1][1]),min(dp[j-1][2],dp[j-1][3]))+1; dp[j][1]=min(min(dp[j-1][0],dp[j-1][1]+1),min(dp[j-1][2]+1,dp[j-1][3]+1)); dp[j][2]=min(min(dp[j-1][0],dp[j-1][1]),min(dp[j-1][2]+1,dp[j-1][3]+1)); dp[j][3]=min(min(dp[j-1][0],dp[j-1][1]),min(dp[j-1][2],dp[j-1][3]+1)); }else if(notes[j]==notes[j-1]){ dp[j][0]=min(min(dp[j-1][0],dp[j-1][1]+1),min(dp[j-1][2]+1,dp[j-1][3]+1)); dp[j][1]=min(min(dp[j-1][0]+1,dp[j-1][1]),min(dp[j-1][2]+1,dp[j-1][3]+1)); dp[j][2]=min(min(dp[j-1][0]+1,dp[j-1][1]+1),min(dp[j-1][2],dp[j-1][3]+1)); dp[j][3]=min(min(dp[j-1][0]+1,dp[j-1][1]+1),min(dp[j-1][2]+1,dp[j-1][3])); }else if(notes[j]<notes[j-1]){ dp[j][0]=min(min(dp[j-1][0]+1,dp[j-1][1]),min(dp[j-1][2],dp[j-1][3])); dp[j][1]=min(min(dp[j-1][0]+1,dp[j-1][1]+1),min(dp[j-1][2],dp[j-1][3])); dp[j][2]=min(min(dp[j-1][0]+1,dp[j-1][1]+1),min(dp[j-1][2]+1,dp[j-1][3])); dp[j][3]=min(min(dp[j-1][0],dp[j-1][1]),min(dp[j-1][2],dp[j-1][3]))+1; } } cout<<min(min(dp[K-1][0],dp[K-1][1]),min(dp[K-1][2],dp[K-1][3])); cout<<endl; } return 0; }
以上是关于Kick Start Round D 2020(前两题)的主要内容,如果未能解决你的问题,请参考以下文章
Round A 2020 - Kick Start 2020
Google Kick Start 2020 Round B T4 Wandering Robot
Round G 2019 - Kick Start 2019