设计建筑物【贪心】

#include <bits/stdc++.h>
using namespace std;
const int maxn=5e5+60;
struct node
{
	int x;
	bool f;
}a[maxn];
bool cmp(node a,node b)
{
	return a.x<b.x;
 } 
int main()
{
	int p;
	scanf("%d",&p);
	for(int kase = 1;kase<=p;kase++)
	{
		int n;
		scanf("%d",&n);
		if(n==0) {
		printf("0\n");continue;}
		for(int i=1;i<=n;i++)
		{
			int x;
			scanf("%d",&x);
			a[i].x=abs(x);
			if(x<0) a[i].f=false;
			else a[i].f=true;
		}
		sort(a+1,a+1+n,cmp);
		bool flag=a[1].f;
		int ans=1;
		for(int i=2;i<=n;i++)
		{
		//	cout<<"a[i]= "<<a[i].x<<endl;
			if(a[i].f!=flag)
			{
				ans++;
				flag=a[i].f;
				//cout<<ans<<" "<<a[i].x<<endl;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
/*
2
5
7
-2
6
9
-3
8
11
-9
2
5
18
17
-15
4

*/
全部评论

相关推荐

神哥不得了:神哥来啦~1.建议不要包装,很容易问穿2.没日常也能找到暑期3.简历模板换一下,字体和版式看着好难受,而且最好压缩到一页,技术的倒数第2和3重复啦,项目建议换两个高质量的上去,如果时间够的话,八股就把高频top50的题目多巩固几遍,吃透,注意不要找假高频,这样绝对能找到暑期
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务