UVa 11039
2016-06-16 16:23
218 查看
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int a[500010];
int cmp(int x,int y)
{
return abs(x) < abs(y);
}
int get(int k)
{
int sum = 0,i = 0;
for(;i<n;)
{
k=-k;
if(k==1)
{
for(;a[i]<0 && i<n;i++);
}
else
{
for(;a[i]>0 && i<n;i++);
}
if(i<n)
sum++;
}
return sum;
}
int main()
{
int T=0;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n,cmp);
printf("%d\n",max( get(1) , get(-1) ));
}
return 0;
}
#include <algorithm>
using namespace std;
int n;
int a[500010];
int cmp(int x,int y)
{
return abs(x) < abs(y);
}
int get(int k)
{
int sum = 0,i = 0;
for(;i<n;)
{
k=-k;
if(k==1)
{
for(;a[i]<0 && i<n;i++);
}
else
{
for(;a[i]>0 && i<n;i++);
}
if(i<n)
sum++;
}
return sum;
}
int main()
{
int T=0;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n,cmp);
printf("%d\n",max( get(1) , get(-1) ));
}
return 0;
}
相关文章推荐
- 1.10055 - Hashmat the brave warrior
- 2.10071 - Back to High School Physics
- 3.458 - The Decoder
- 4.694 - The Collatz Sequence
- 6.494 - Kindergarten Counting Game
- 7.490 - Rotating Sentences
- 8.414 - Machined Surfaces
- 9.488 - Triangle Wave
- A.457 - Linear Cellular Automata
- B.489 - Hangman Judge
- C.445 - Marvelous Mazes
- 1.10494 - If We Were a Child Again
- 2.424 - Integer Inquiry
- 3.10250 - The Other Two Trees
- 5.465 - Overflow
- 6.113 - Power of Cryptography
- 7.10161 - Ant on a Chessboard
- 8.621 - Secret Research
- 9.401 - Palindromes
- A.537 - Artificial Intelligence?