Uva11039 Building design...

水题:根据绝对值大小排序,遍历即可

#include 
#include 
#include 
#include 
using namespace std;
struct num{
	int val,symbol;
	friend bool operator <(num a,num b){
		return a.val> ncase;
	vector g;
	while(ncase--){
		g.clear();
		int n;
		scanf("%d",&n);
		for(int i = 0; i < n; i++){
			int tmp;
			num t;
			scanf("%d",&tmp);
			if(tmp > 0){
				t.val = tmp;
				t.symbol = 1;
			}else{
				t.val = -tmp;
				t.symbol = 0;
			}
			g.push_back(t);
		}
		sort(g.begin(),g.end());
		int ans = 1;
		bool flag = g[0].symbol;
		for(int i = 1; i < g.size(); i++){
			while(flag == g[i].symbol && i < g.size()){
				i++;
			}
			if(flag != g[i].symbol && i < g.size()){
				ans++;
				flag = g[i].symbol;
			}
		}
		cout<


你可能感兴趣的:(模拟)