UVA 11039 - Building designing(DP)
2013-10-29 20:19
323 查看
题目链接
本质上是DP,但是俩变量就搞定了。
本质上是DP,但是俩变量就搞定了。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int p[500001]; bool cmp(int a,int b) { if(a < 0) a = -a; if(b < 0) b = -b; return a < b; } int main() { int t,n,p1,p2,i; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i = 0;i < n;i ++) { scanf("%d",&p[i]); } sort(p,p+n,cmp); p1 = p2 = 0; for(i = 0;i < n;i ++) { if(p[i] > 0) p1 = p2 + 1; else p2 = p1 + 1; } printf("%d\n",max(p1,p2)); } }
相关文章推荐
- UVA.10130 SuperSale (DP 01背包)
- UVa 1218 - Perfect Service(树形DP)
- UVA 1371 - Period(DP)
- Placing Lampposts - UVa 10859 树形dp
- DP优化——四边形不等式 uva 10304 - Optimal Binary Search Tree
- 100道动态规划——4 UVA 1331 Maximum Triangulation DP 计算几何
- uva 6952 Cent Savings dp
- UVA - 11468 Substring (AC自动机 + 概率dp)
- uva_10913 - Walking on a Grid( 普通DP )
- Uva 10859 - Placing Lampposts 树形dp
- UVALive 4811 Growing Strings【AC自动机+简单dp】
- UVA10440->贪心||DP
- UVa 10739 String to Palindrome (DP)
- UVa 10828 Back to Kernighan-Ritchie 高斯消元+概率DP
- uva 10201 Adventures in Moving - Part IV (DP)
- Uva 10817 - Headmaster's Headache(状态压缩DP)
- Uva-825 Walking on the Safe Side 水DP
- UVa 10913 - Walking on a Grid(dp递推变形)
- UVa 10003 - Cutting Sticks(白书,区间DP)
- 【DP】UVA 10003 Cutting Sticks 类似矩阵链乘