/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
vector< pair<ll, ll> >data ;
int main()
{
int test ;
cin>>test ;
while(test--)
{
int flor,n ;
cin>>flor ;
while(flor--)
{
cin>>n ;
if(n>0)
data.pb(make_pair(n,n)) ;
else if(n<0)
data.pb(make_pair((-1*n),n)) ;
}
sort(data.begin() , data.end()) ;
int cnt =0 ;
for(int i=0 ; i<data.size()-1 ; i++)
{
if(data[i].second>0 && data[i+1].second<0)
cnt++ ;
else if(data[i].second<0 && data[i+1].second>0)
cnt++ ;
}
if(cnt==0)
cnt++ ;
else
cnt++ ;
pf("%d\n",cnt) ;
data.clear() ;
}
return 0;
}
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
vector< pair<ll, ll> >data ;
int main()
{
int test ;
cin>>test ;
while(test--)
{
int flor,n ;
cin>>flor ;
while(flor--)
{
cin>>n ;
if(n>0)
data.pb(make_pair(n,n)) ;
else if(n<0)
data.pb(make_pair((-1*n),n)) ;
}
sort(data.begin() , data.end()) ;
int cnt =0 ;
for(int i=0 ; i<data.size()-1 ; i++)
{
if(data[i].second>0 && data[i+1].second<0)
cnt++ ;
else if(data[i].second<0 && data[i+1].second>0)
cnt++ ;
}
if(cnt==0)
cnt++ ;
else
cnt++ ;
pf("%d\n",cnt) ;
data.clear() ;
}
return 0;
}
No comments:
Post a Comment