题解
2023-06-27 19:43:29
发布于:上海
82阅读
0回复
0点赞
#include<bits/stdc++.h>
#define R register
#define us unsigned
#define ll R long long
const int size=(1<<20)+1;char buf[size],*p1=buf,*p2=buf;char buffer[size];int op1=-1;const int op2=size-1;inline char readchar(){if(p1!=p2){return*p1++;}return p1==(p2=(p1=buf)+fread(buf,1,size-1,stdin))?EOF:*p1++;}inline void flush(){fwrite(buffer,1,op1+1,stdout),op1=-1;}inline void writechar(const char&x){if(op1==op2)flush();buffer[++op1]=x;}
#ifndef ONLINE_JUDGE
#define readchar getchar
#endif
#define putchar writechar
inline long long read(){ll s=1,c=readchar(),x=0;while(c<=32){c=readchar();}if(c=='-'){s=-1,c=readchar();}for(;('0'<=c&&c<='9');c=readchar()){x=x*10+c-'0';}return x*s;}inline void write(long long x){if(x<0){writechar('-'),x=-x;}char s[25];ll n=0;while(x||!n){s[n++]='0'+x%10,x/=10;}while(n--){writechar(s[n]);}}
using namespace std;
bool f(ll a,ll b,ll c){
int zheng=0,fu=0;
if(a<0)fu++;
else if(a>=0)zheng++;
if(b<0)fu++;
else if(b>=0)zheng++;
if(c<0)fu++;
else if(c>=0)zheng++;
if(zheng<fu)return true;
else return false;
}
int main(){
int n;
ll a[100005];
cin>>n;
ll t1,t2,t3;
for(int i=0;i<n;i++)a[i]=read();
for(int i=0;i<n-2;i++){
bool fg=f(a[i],a[i+1],a[i+2]);
t1=a[i],t2=a[i+1],t3=a[i+2];
if(fg)a[i]=t2,a[i+1]=t3,a[i+2]=t1;
else a[i]=t3,a[i+1]=t2,a[i+2]=t1;
}
for(int i=0;i<n;i++)write(a[i]),putchar(' ');
flush();
return 0;
}
这里空空如也
有帮助,赞一个