版本比较
10.1 考试总结
正文
增加 84 行删除 1 行
259 行未改动全部展开260261262263264264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351259 行未改动全部展开 (2) 当前吃了过后是最小,那么需要考虑次大值是否会吃,仍然是递归下去。 - 可以看出这个递归没有分支,那么终点就是如果只剩自己一人,那么一定吃,如果自己会死,那么不吃- 用两个队列优化即可#### code还没写出来......```cpp line-numbers#include<bits/stdc++.h>#define PII pair<int,int> #define mk make_pairusing namespace std;inline int read() { int s=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch<='9'&&ch>='0'){s=s*10+ch-'0';ch=getchar();} return s*f;}const int N=1e6+5,mod=998244353;int T,n,m,ans;int a[N],du[N],op[N];deque<PII> q1,q2,q;void solve(){ q1.clear(),q2.clear(),q.clear(); for(int i=1;i<=n;i++) q1.push_back(mk(a[i],i)); while(true){ if(q1.size()+q2.size()==2){ cout<<"1\n"; return ; } PII st=q1.front(); q1.pop_front(); PII ed=q1.back(); if(!q2.empty() && q2.back()>ed){ ed=q2.back(); q2.pop_back(); }else q1.pop_back(); PII tmp=mk(ed.first-st.first,ed.second); if(q1.front()<tmp) q2.push_front(tmp);//直接吃 else { q1.push_front(tmp); break; } } while(!q1.empty() && !q2.empty()){ if(q1.front()<q2.front()){ q.push_back(q1.front()); q1.pop_front(); }else { q.push_back(q2.front()); q2.pop_front(); } } while(!q1.empty()){ q.push_back(q1.front()); q1.pop_front(); } while(!q2.empty()){ q.push_back(q2.front()); q2.pop_front(); } int now=q.size(),cnt=0;//cnt表示吃的次数,如果是奇数,那么不吃,否则能活,就吃 while(q.size()>1){ PII st=q.front(),ed=q.back(); q.pop_front(),q.pop_back(); cnt++; PII tmp=mk(ed.first-st.first,ed.second); if(q.front()<tmp || q.size()==0) break; else q.push_front(tmp); } cout<<now+cnt%2<<'\n'; return ;}signed main(){ T=read(); n=read(); for(int i=1;i<=n;i++) a[i]=read(); T--; solve(); while(T--){ int k=read(); for(int i=1;i<=k;i++){ int x=read(),y=read(); a[x]=y; } solve(); } return 0;}```## 总结- 代码能力弱- 考场时间分布不优- 细节问题