提交时间:2024-04-18 13:39:04

运行 ID: 143767

#include<bits/stdc++.h> using namespace std; int read(){ int ans=0; char ch=getchar(),last=' '; while(ch<'0'||ch>'9'){ last=ch; ch=getchar(); } while(ch>='0'&&ch<='9'){ ans=(ans<<3)+(ans<<1)+ch-'0'; ch=getchar(); } return last=='-'?-ans:ans; } int n,dl[10001],ans[10001],ans2[10001]; bool flag1,flag0; inline void print(){ for(int i=1;i<=n;i++)cout<<ans[i]<<" "; } inline void print2(){ for(int i=1;i<=n;i++)cout<<ans2[i]<<" "; } int main(){ n=read(); for(int i=1;i<=n;i++)dl[i]=read(); ans[1]=1; for(int i=1;i<=n;i++){ if(i==1){ ans[2]=dl[1]-ans[1]; if(ans[2]<0||ans[2]>1)flag1=1; } if(i==n&&dl[i]-ans[i-1]-ans[i]!=0)flag1=1; else{ ans[i+1]=dl[i]-ans[i-1]-ans[i]; if(ans[i+1]<0||ans[i+1]>1)flag1=1; } } for(int i=1;i<=n;i++){ if(i==1){ ans2[2]=dl[1]-ans2[1]; if(ans2[2]<0||ans2[2]>1)flag0=1; } if(i==n&&dl[i]-ans2[i-1]-ans2[i]!=0)flag0=1; else{ ans2[i+1]=dl[i]-ans2[i-1]-ans2[i]; if(ans2[i+1]<0||ans2[i+1]>1)flag0=1; } } if(flag1==1&&flag0==0)print2(); else if(flag1==0&&flag0==1)print(); else if(flag1==0&&flag0==0)print(); else cout<<"No answer"; return 0; }