uva11039

很2b的排序负数在前,整数在后,然后模拟过程,半天没搞出来。

换了方法,对绝对值排序。搞出来了。

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
int Array[500010];
int cmp(int a,int b)
{
    return abs(a)<abs(b);
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        for(int i=0; i<n; i++)
        {
            scanf("%d",&Array[i]);
        }
        sort(Array,Array+n,cmp);
        int temp;
        if(Array[0]<0)
        {
            temp=-1;
        }
        else
        {
            temp=1;
        }
        int ans=1;
        for(int i=1;i<n;i++)
        {
            if(Array[i]*temp<0)
            {
                ans++;
                temp*=-1;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

posted @ 2014-10-19 22:28  名牌果果  阅读(188)  评论(0编辑  收藏  举报