A题
签到模拟
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pll; const int inf=0x3f3f3f3f; const int N=1e5+10; const int mod=1e9+7; int a[N]; int main(){ ios::sync_with_stdio(false); int n; cin>>n; int i; for(i=1;i<=n;i++){ cin>>a[i]; } if(n==1){ cout<<"-1"<<endl; } else if(n==2){ if(a[1]==a[2]){ cout<<-1<<endl; } else{ cout<<1<<endl; cout<<1<<endl; } } else{ int mx=0x3f3f3f3f; cout<<1<<endl; int id; for(i=1;i<=n;i++){ if(mx>a[i]){ mx=a[i]; id=i; } } cout<<id<<endl; } return 0; }
B题
按奇数偶数分,然后排序贪心求解
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pll; const int inf=0x3f3f3f3f; const int N=1e5+10; const int mod=1e9+7; vector<int> num; int a[N]; int main(){ ios::sync_with_stdio(false); int n,b; cin>>n>>b; int i; int cnt1=0; int cnt2=0; for(i=1;i<=n;i++) cin>>a[i]; for(i=1;i<=n;i++){ if(a[i]%2){ cnt1++; } else{ cnt2++; } if(cnt1==cnt2){ if(i+1<=n){ num.push_back(abs(a[i+1]-a[i])); } } } sort(num.begin(),num.end()); int ans=0; int cnt=0; while(b){ if(cnt==(int)num.size()) break; if(b-num[cnt]<0) break; ans++; b-=num[cnt]; cnt++; } cout<<ans<<endl; return 0; }
C题
我们发现每次反转都会少了全0子串,所以贪心判断即可
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pll; const int inf=0x3f3f3f3f; const int N=1e5+10; const int mod=1e9+7; int main(){ ios::sync_with_stdio(false); int n,x,y; cin>>n>>x>>y; string s; cin>>s; int i; if(x>y){ ll ans=0; for(i=0;i<(int)s.size();i++){ if(s[i]=='0'){ ans+=y; while(i<(int)s.size()-1&&s[i+1]=='0') i++; } } cout<<ans<<endl; } else{ ll ans=y; int cnt=0; for(i=0;i<(int)s.size();i++){ if(s[i]=='0'){ cnt++; while(i<(int)s.size()-1&&s[i+1]=='0') i++; } } if(cnt==0){ cout<<0<<endl; } else cout<<ans+(ll)x*(cnt-1)<<endl; } return 0; }
D题
这种题显然就是找规律,找到前12个后,后面的规律就比较明显了
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=5e5+10; int d[]={0,4,10,20,35,56,83,116,155,198,244,292}; int main(){ ios::sync_with_stdio(false); ll n; cin>>n; if(n<=11){ cout<<d[n]<<endl; } else{ ll ans=292; cout<<ans+(ll)(n-11)*49<<endl; } }