题解:CF2102B The Picky Cat
题意
给出一个数
思路
在输入数组时每一项都取其绝对值,然后进行从小到大的排序,令 YES,否则为 NO。
解释
当 YES。
当 NO。
Code
#include<bits/stdc++.h>
#define N 100086
#define ll long long
#define iakioi cout<<"I AK IOI"<<endl
using namespace std;
struct node{
int snum,id; //id表示原数组中第几个输入的数,方便找到a[1],snum则为其绝对值
}a[N];
int t,n;
inline int read();
inline bool cmp(node x,node y);
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
t=read();
while(t--){
n=read();
int mid=n/2;
for(int i=1;i<=n;i++){
a[i].snum=abs(read());
a[i].id=i;
}
sort(a+1,a+1+n,cmp); //按绝对值从小到大排序
int cnt=0;
for(int i=1;i<=n;i++){
if(a[i].id==1) break; //寻找绝对值小于a[1]的绝对值的数的个数
cnt++;
}
if(cnt<=mid) cout<<"YES"<<endl; //判断
else cout<<"NO"<<endl;
}
return 0;
}
inline int read(){
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-48;ch=getchar();}
return x*f;
}
inline bool cmp(node x,node y){
return x.snum<y.snum;
}