这场好像没什么人打,莫名其妙就上分了。
甚至获得了青名体验卡,不过下一场应该就掉下去了。
一个很显然的贪心构造
| #include<bits/stdc++.h> |
| using namespace std; |
| template<typename T>inline void re(T &x) |
| { |
| x=0;int f=1;char c=getchar(); |
| while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} |
| while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();} |
| x*=f; |
| } |
| template<typename T>inline void wr(T x) |
| { |
| if(x<0)putchar('-'),x=-x; |
| if(x>9)wr(x/10); |
| putchar(x%10^48); |
| } |
| inline void out(int x){wr(x),putchar('\n');} |
| int n,T; |
| int X,Y,K; |
| inline void solve() |
| { |
| int len=min(X,Y); |
| printf("0 0 %d %d\n0 %d %d 0\n",len,len,len,len); |
| } |
| int main() |
| { |
| re(T); |
| while(T--) |
| { |
| cin>>X>>Y>>K; |
| solve(); |
| } |
| return 0; |
| } |
还是个贪心,一开始写个了 的算法,结果吃了一次罚时,回头发现 ,好像如果 线性能过,应该不会给这么小的数据,那么想想是否可以 。
好像确实有所遗漏,实际上每个点都可以单独拎出来考虑( 为奇数的情况下)。
所以最后是 的。
这题要是再多一发罚时,就上不了青了,或许会少一些烦恼。
| #include<bits/stdc++.h> |
| #define int long long |
| using namespace std; |
| template<typename T>inline void re(T &x) |
| { |
| x=0;int f=1;char c=getchar(); |
| while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} |
| while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();} |
| x*=f; |
| } |
| template<typename T>inline void wr(T x) |
| { |
| if(x<0)putchar('-'),x=-x; |
| if(x>9)wr(x/10); |
| putchar(x%10^48); |
| } |
| inline void out(int x){wr(x),putchar('\n');} |
| int n,T; |
| int a[100000]; |
| int ban; |
| int nex(int x) |
| { |
| return ban==x+1?x+2:x+1; |
| } |
| inline void solve() |
| { |
| int ans=1; |
| if(n%2==1) |
| { |
| ans=1e18+10; |
| for(register int b=1;b<=n;++b) |
| { |
| ban=b; |
| int tmp=1; |
| for(register int i=1;i<=n;i+=2) |
| { |
| if(i==b) |
| { |
| i--; |
| continue; |
| } |
| tmp=max(tmp,a[nex(i)]-a[i]); |
| if(i+1==b)i++; |
| } |
| ans=min(ans,tmp); |
| } |
| } |
| else |
| for(register int i=1;i<=n-1;i+=2)ans=max(ans,a[i+1]-a[i]); |
| out(ans); |
| } |
| signed main() |
| { |
| re(T); |
| while(T--) |
| { |
| re(n); |
| for(register int i=1;i<=n;++i) |
| re(a[i]); |
| solve(); |
| } |
| return 0; |
| } |
| |
| |
| |
写了个莫名其妙但是很正确的贪心,然后就过了,幸好没人hack,我也不知道正不正确。
| #include<bits/stdc++.h> |
| #define int long long |
| using namespace std; |
| template<typename T>inline void re(T &x) |
| { |
| x=0;int f=1;char c=getchar(); |
| while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} |
| while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();} |
| x*=f; |
| } |
| template<typename T>inline void wr(T x) |
| { |
| if(x<0)putchar('-'),x=-x; |
| if(x>9)wr(x/10); |
| putchar(x%10^48); |
| } |
| inline void out(int x){wr(x),putchar('\n');} |
| int n,m,T; |
| char s[400010]; |
| signed main() |
| { |
| re(T); |
| while(T--) |
| { |
| int n; |
| re(n); |
| scanf("%s",s+1); |
| int res0=0,res1=0,used0=0; |
| for(register int i=1;i<=n;++i) |
| { |
| if(s[i]=='1')res1++; |
| else res0++; |
| } |
| int ans=n*(n+1)/2; |
| for(register int i=n;i>=1;--i) |
| { |
| |
| if(s[i]=='1') |
| { |
| if(res0>0) |
| { |
| res0--; |
| used0++; |
| ans-=i; |
| } |
| else if(res0==0&&res1>=2) |
| { |
| res1--; |
| ans-=i; |
| } |
| res1--; |
| if(res1==0)break; |
| } |
| else |
| { |
| if(used0>0) |
| { |
| used0--; |
| continue; |
| } |
| if(res0>0)res0--; |
| } |
| } |
| out(ans); |
| } |
| return 0; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
之后应该不会写太多单独的Review了。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效