赞
踩
这场其实有难度。(还是自己菜)
直接按照题意暴力,搞,但是不能只判断是否奇数或者偶数没有 c h a n g e change change 了。要全部判断 m m p mmp mmp,卡了半个小时
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+10,mod=1e9+7; template<typename T> void Debug(T x,string s){ cout<<s<<": "<<x<<endl; } int a[N]; #define PII pair<int,int> #define x first #define y second #define PB push_back map<ll,bool> vis; void solve() { int n;cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } long long cnt=1; long long ans=0; while(1){ bool flag=0; if(cnt&1){ for(int i=1;i<n;i+=2){ if(a[i]>a[i+1]) { swap(a[i],a[i+1]); flag=1; } } } else{ for(int i=2;i<n;i+=2){ if(a[i]>a[i+1]){ swap(a[i],a[i+1]); flag=1; } } } if(flag){ ans++; } else break; cnt++; } cout<<ans<<endl; } int main() { #ifndef ONLINE_JUDGE freopen("a.txt", "r", stdin); freopen("aout.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) solve(); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+10,mod=1e9+7; template<typename T> void Debug(T x,string s){ cout<<s<<": "<<x<<endl; } int a[N]; #define PII pair<int,int> #define x first #define y second #define PB push_back map<ll,bool> vis; void solve() { int n;cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } long long cnt=1; long long ans=0; while(1){ bool flag=0; for(int i=1;i<n;i++){ if(a[i]>a[i+1]) { flag=1; } } if(cnt&1){ for(int i=1;i<n;i+=2){ if(a[i]>a[i+1]) { swap(a[i],a[i+1]); } } } else{ for(int i=2;i<n;i+=2){ if(a[i]>a[i+1]){ swap(a[i],a[i+1]); } } } if(flag){ ans++; } else break; cnt++; } cout<<ans<<endl; } int main() { #ifndef ONLINE_JUDGE freopen("a.txt", "r", stdin); freopen("aout.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) solve(); }
设 a a a 为较小的那一个,设 t t t = a + b 2 \frac{a+b}{2} 2a+b。
①、 a + b a+b a+b 为偶数。
分别讨论
| 其中一个人 break的场次 | 总共break的场次 |
|---|---|
| 0 | a-0+t-0=a+t |
| 1 | a-1+t-1=a+t-2 |
| 2 | a-2+t-2=a+t-2*2 |
| … | … |
| a | a-a+t-a=t-a |
②、 a + b a+b a+b 为奇数
当 a a a 的场次为 t t t时,和上面一样;当 a a a 的场次为 t + 1 t+1 t+1 时
| 其中一个人 break的场次 | 总共break的场次 |
|---|---|
| 0 | a-0+t+1-0=a+t+1 |
| 1 | a-1+t+1-1=a+t-1 |
| 2 | a-2+t+1-2=a+t-3 |
| … | … |
| a | a-a+t+1-a=t+1-a |
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+10,mod=1e9+7; template<typename T> void Debug(T x,string s){ cout<<s<<": "<<x<<endl; } int a[N]; #define PII pair<int,int> #define x first #define y second #define PB push_back map<ll,bool> vis; void solve() { int a,b;cin>>a>>b; // if(a==b){ // cout<<(a+b)/2+1<<endl; // for(int i=0;i<=(a+b);i+=2){ // cout<<i<<" "; // } // cout<<endl;return; // } if(a>b) swap(a,b); int sum=(a+b); if(sum%2==0){ cout<<a+1<<endl; for(int i=sum/2-a;i<=a+sum/2;i+=2){ cout<<i<<" "; } cout<<endl; } else{ cout<<2*a+2<<endl; int tx=sum/2; for(int i=tx-a;i<=tx+1+a;i++){ cout<<i<<" "; } cout<<endl; } } int main() { #ifndef ONLINE_JUDGE freopen("a.txt", "r", stdin); freopen("aout.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) solve(); }
贪心搞,处理出每个洞的最小需求,然后遍历比较求出所有的最小需求
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+10,mod=1e9+7; template<typename T> void Debug(T x,string s){ cout<<s<<": "<<x<<endl; } int a[N]; #define PII pair<ll,ll> #define x first #define y second #define PB push_back map<ll,bool> vis; void solve() { int n;cin>>n; vector<ll> vec[n+1]; vector<PII> ans; for(int i=1;i<=n;i++){ int k;cin>>k; for(int j=1;j<=k;j++){ int tx;cin>>tx; vec[i].push_back(tx); } for(int j=k-2;j>=0;j--){ vec[i][j]=max(vec[i][j+1]-1,vec[i][j]); } ans.push_back({vec[i][0]+1,k*1ll}); } sort(ans.begin(),ans.end()); ll anss = ans[0].x; ll tans = anss + ans[0].y; ll pat=ans[0].y; for(int i=1;i<ans.size();i++){ if(tans>ans[i].x){ tans+=ans[i].y; } else{ anss=min(anss+ans[i].x-tans,ans[i].x-pat); tans=ans[i].x+ans[i].y; } pat+=ans[i].y; } cout<<anss<<endl; } int main() { #ifndef ONLINE_JUDGE freopen("a.txt", "r", stdin); freopen("aout.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) solve(); }
好像是个数论分块,加dp,稍后补上。
思路
数论分块

代码
#include<cstdio> const int N=2e5+10; int n,mod; long long ans,dp[N]; int main() { scanf("%d%d",&n,&mod); dp[1]=1;ans=1; for(int i=2;i<=n;i++) { dp[i]=ans; for(int l=2,r;l<=i;l=r+1) { r=i/(i/l); dp[i]=(dp[i]+dp[i/l]*(r-l+1))%mod; } ans=(dp[i]+ans)%mod; } printf("%lld",dp[n]); return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。