UVA 11039

  Building designing 

An architect wants to design a very high building. The building will consist of some floors, and each floor has a certain size. The size of a floor must be greater than the size of the floor immediately above it. In addition, the designer (who is a fan of a famous Spanish football 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 building the architect has n available floors, with their associated sizes and colours. All the available floors are of different sizes. The architect wants to design the highest possible building with these restrictions, using the available floors.

Input 

The input file consists of a first line with the number p of cases to solve. The first line of each case contains the number of available floors. Then, the size and colour of each floor appear in one line. Each floor is represented with an integer between -999999 and 999999. There is no floor with size 0. Negative numbers represent red floors and positive 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 consist of a line with the number of floors of the highest building with the mentioned conditions. 

Sample Input 

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

Sample Output 

 
2
5

1Y的水题,不解释了,小模拟

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include <string>
#include <stack>
#include <cctype>
#include <vector>
#include <queue>
#include <set>

using namespace std;
const int MAXN = 500000 + 50;
const int maxw = 100 + 20;
const long long LLMAX = 0x7fffffffffffffffLL;
const long long LLMIN = 0x8000000000000000LL;
const int INF = 0x7fffffff;
const int IMIN = 0x80000000;
#define eps 1e10-8
#define mod 1000000007
typedef long long LL;
const double PI = acos(-1.0);
typedef double D;
//#define Online_Judge
#define outstars cout << "***********************" << endl;
#define clr(a,b) memset(a,b,sizeof(a))

#define clr(a,b) memset(a,b,sizeof(a))
#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)
#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)
#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)
#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)
int a[MAXN];
int main()
{
    #ifdef Online_Judge
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif // Online_Judge
    int T , n;
    cin >> T;
    while(T--)
    {
        scanf("%d",&n);
        FOR(i , 0 , n)
        {
            scanf("%d",&a[i]);
        }
        a[n] = 0;

        sort(a  , a + n + 1);
//        FORR(i ,0 , n)cout << a[i]<<' ' ;
//        cout << endl;
        int key = 0;
        FORR(i , 0 , n )
        {
            if(a[i] == 0)key = i;
        }
        int i , j , ans = 0;
        i = key - 1;
        j = key + 1;
        int turn;///下一次向哪边取 , 1为右 , 0为左
        int sign = 0;
        if(abs(a[i]) < abs(a[j]))
        {
            turn = 1;
            ans++;
            sign = a[i];
            i--;
        }
        else
        {
            turn = 0;
            ans++;
            sign = a[j];
            j++;
        }
//        cout << "  " << sign <<endl;
        while(i >= 0 || j <= n)
        {
            if(!turn)
            {
                if(abs(a[i]) > abs(sign))
                {

                    ans++;
                    sign = a[i];
                    i--;
                    turn = 1;
                }
                else i--;
            }
            else
            {
                if(abs(a[j]) > abs(sign))
                {

                    ans++;
                    sign = a[j];
                    j++;
                    turn = 0;
                }
                else j++;
            }
            if(i < 0&&!turn)break;
            if(j > n&&turn)break;
//            cout << ' ' << sign << endl;
        }
        printf("%d\n",ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值