11039 - Building designing


 Building designing 

An architect wants to design a very highbuilding. The building will consist of some floors, and each floor has a certainsize. The size of a floor must be greater than the size of the floorimmediately above it. In addition, the designer (who is a fan of a famous Spanishfootball team) wants to paint the building in blue and red, each floor a colour,and in such a way that the colours of two consecutive floors are different.

To design the buildingthe architect has n available floors, withtheir associated sizes and colours. All the available floors are of different sizes. The architect wants todesign the highest possible building with these restrictions, using the available floors.

Input 

The input file consists of a firstline with the number p of cases to solve. The first line of each case containsthe number of available floors. Then, the size and colour of each floor appear inone line. Each floor is represented with an integer between -999999 and 999999.There is no floor with size 0. Negative numbers represent red floors andpositive numbers blue floors. The size of the floor is the absolute value of the number.There are not two floors with the same size.The maximum number of floors for a problem is 500000.

Output 

For each case the output will consistof a line with the number of floors of the highest building with the mentionedconditions. 

Sample Input 

 
2
5
7
-2
6
9
-3
8
11
-9
2
5
18
17
-15
4

Sample Output 

 
2
5



#include<iostream>
#include<algorithm>
using namespace std;
int a[500005];
int cmp(int a, int b)  
{  
	return abs(a) < abs(b);  
}  

int main()
{
	int t,n,i;
	cin>>t;
	while(t--)
	{
		cin>>n;
		int count=1;
		for(i=0;i<n;i++)
			cin>>a[i];
		sort(a,a+n,cmp);
		int f=a[0]/abs(a[0]);
		for(i=1;i<n;i++)
		{
			if(a[i]*f< 0)
			{
				count++;
				f*= -1;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值