UVa 11039 Building designing (模拟)
2013-09-01 22:20
253 查看
11039 - Building designing
Time limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=457&page=show_problem&problem=1980
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 numberof 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
water.
完整代码:
/*0.072s*/ #include<cstdio> #include<algorithm> using namespace std; struct Floor { bool blue; int size; bool operator < (const Floor &f) const { return size < f.size; } } floor[500010]; int main(void) { int p, temp; scanf("%d", &p); while (p--) { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &temp); floor[i] = temp > 0 ? (Floor){true, temp} : (Floor){false, -temp}; } sort(floor, floor + n); bool nowblue = floor[0].blue; int count = 1; for (int i = 1; i < n; ++i) { if (floor[i].blue != nowblue) { nowblue = !nowblue; ++count; } } printf("%d\n", count); } return 0; }
相关文章推荐
- UVA 11039(模拟,贪心)
- UVA 11039 模拟
- UVA 11039 模拟
- UVALive - 7511 Multiplication Table (模拟)
- UVa 101 The Blocks Problem 【STL】【vector】【模拟】
- UVA 221 Urban Elevations 离散化 模拟
- UVa 227 模拟
- UVa 11039 Building designing (贪心+排序+模拟)
- UVA 706 LCD Display 液晶显示屏 (字符串模拟)
- UVA - 10881-Piotr's Ants-思路题/模拟
- UVA 12657(双向链表模拟)
- UVA 514 - Rails(模拟)
- uva 11384 Help is needed for Dexter(模拟)
- UVA 1593: Alignment of Code(模拟 Grade D)
- uva133 The Dole Queue 循环队列模拟
- uva 101 The Blocks Problem (模拟)
- uva 11210 - Chinese Mahjong(模拟,3级)
- UVA11039- Building designing
- UVA 246 - 10-20-30 (模拟+STL)
- UVALive 6832 Bit String Reordering (模拟)