zoukankan      html  css  js  c++  java
  • K

    K - Building designing
    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
    Submit Status

    Description

    Download as PDF
     

     

      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
    

     
    const int INF = 1000000000;
    const double eps = 1e-8;
    const int maxn = 510000;
    
    int num[maxn];
    int dp[maxn];
    bool cmp(int a,int b)
    {
        return abs(a) < abs(b);
    }
    bool diff(int a,int b)
    {
        if(a > 0 && b < 0)
            return true;
        if(a < 0 && b > 0)
            return true;
        return false;
    }
    int main() 
    {
        //freopen("in.txt","r",stdin);
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int n;
            scanf("%d",&n);
            repf(i,1,n)
                scanf("%d",&num[i]);
            
            //cout<<"num"<<num[1]<<endl;
            sort(num+1,num+1+n,cmp);
           //  cout<<"num"<<num[1]<<endl;
            dp[1] = 1;
            
            repf(i,2,n)
            {
                if(diff(num[i],num[i-1]))
                    dp[i] = dp[i-1] + 1;
                else
                    dp[i] = dp[i-1];
            }
            cout<<dp[n]<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Python基础5_字典,集合
    Python基础3_基本数据类型,字符串,for循环
    Python基础2_while循环,格式化输出,基本运算符,编码,
    Python基础1_初识,注释,变量,if语句
    编写高质量代码[读书笔记]
    php地方天气
    [head first php&mysql]读书笔记-基本的安全信息(第五章)
    上传本地图片
    检测IE
    underscore源码解析(实用的功能)
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3436323.html
Copyright © 2011-2022 走看看