UVA 11039 - Building designing
来源:互联网 发布:食品伙伴网数据库 编辑:程序博客网 时间:2024/05/17 03:40
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
257-269-3811-9251817-154
Sample Output
25
题意:给定一个序列,要求选出一个子序列排列出一正一负交替并且绝对值递增,求子序列最长长度。
思路:先按绝对值排序,然后一个个去枚举,如果不和之前一个同正或同负就+1.
代码:
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int N = 500005;int t, n, num[N];bool cmp(int a, int b) { return abs(a) < abs(b);}void init() { scanf("%d", &n); for (int i = 0; i < n; i ++)scanf("%d", &num[i]); sort(num, num + n, cmp);}int solve() { int ans = 1, flag = 0; if (num[0] < 0) flag = 0; else flag = 1; for (int i = 1; i < n; i ++) {if (flag == 0 && num[i] > 0) { flag = 1; ans ++;}else if (flag == 1 && num[i] < 0) { flag = 0; ans ++;} } return ans;}int main () { scanf("%d", &t); while (t--) {init();printf("%d\n", solve()); } return 0;}
- UVA 11039 Building designing
- UVA 11039 - Building designing
- uva 11039 - Building designing
- Uva-11039-Building designing
- UVa 11039 - Building designing
- Uva - 11039 - Building designing
- UVA 11039 - Building designing
- uva 11039 Building designing
- Uva 11039 - Building designing
- UVA 11039 - Building designing
- UVA - 11039 Building designing
- UVA 11039 Building designing
- UVA 11039 Building designing
- UVA - 11039 Building designing
- UVa 11039 - Building Designing
- UVa 11039 - Building designing
- UVA - 11039 Building designing
- UVA 11039 Building Designing
- 无法将类型为 excel.applicationclass 的 com 强制转换为接口类型 的解决方法。
- 2013 ACM-ICPC 长沙赛区 部分分析
- C#读取设置Cookie
- CSDN高校俱乐部2013年秋季北京地区第一站“编程语言的应用及其发展”—北京联合大学
- 细说Linux系统优化-实践篇
- UVA 11039 - Building designing
- web service 截取网页内容
- nyoj——244 16进制的简单运算
- 当使用vim时遇到Taglist: Exuberant ctags (http://ctags.sf.net) not found in PATH. Plugin is not loaded.
- HDOJ 1059 Dividing (多重背包例题)
- IOS开发之UIScrollView控件详解
- unity NGUI基础
- toString 简单介绍
- ubuntu/debian下apt-get问题总结