csu 1008 Horcrux
2012-03-18 23:39
239 查看
换成栈就解决了超时,时间上还可以优化。
# include <stdio.h> # include <memory.h> # define MAXN 100005 unsigned short s[MAXN]; int top; int main() { int n, x, i, f, t, tot, top; while (~scanf("%d", &n)) { f = top = tot = 0; memset(s, 0, sizeof(s)); if (n) scanf("%d", &f); t = f; s[++top] = 1; for (i = 1; i < n; ++i) { scanf("%d", &x); if (f ^ x) { f = x; if (i%2 && top) { if (top > 1) {s[top-1] += s[top]+1;--top;} else {++s[top]; t = !t;} } else s[++top] = 1; } else ++s[top]; } if ((top%2) == t) --top; while (top > 0) { tot += s[top]; top -= 2; } printf("%d\n", tot); } return 0; }
相关文章推荐
- csu 1008 - Horcrux
- CSU1008 Horcrux (模拟)
- CSUOJ 1008 Horcrux
- CSU1008-Horcrux-栈
- COJ-1008-Horcrux
- csu oj 1008 Horcrux(计数)
- CSU 1566 The Maze Makers
- 1008: [HNOI2008]越狱
- POJ 1008 Maya Calendar GCC编译
- RAC的GCS和GES 转载自http://blog.csdn.net/csucxcc/archive/2010/09/02/5857373.asp
- 【LigntOj】-1008- Fibsieve`s Fantabulous Birthday
- 1008. Elevator (20)
- csu 1110 RMQ with Shifts 线段树
- PAT (Top Level) Practise 1008 Airline Routes (35) (tarjan算法求强联通分量)【四星级】
- CSU 1729: 齿轮传动
- linux中使用select和epoll确定异步connect连接是否成功 标签: 网络编程服务器异步connectSO_ERRORsocket 2016-07-31 23:07 1008人阅读 评
- 关于CSU 1725以及CodeForce 148D自己的解法
- CSU 1522: Extravagant number
- CSU 1660 搜索 在图中寻找一个长度为K的环
- csu 1769(数学)