BZOJ1753 [Usaco2005 qua]Who's in the Middle
2014-11-08 19:41
447 查看
直接快排没意思。。。
于是想写写"快速选择算法"。。。结果啊。。。
调了1h。。。欧我去。。。至于么,已经蒟蒻到这种程度了?
反正我是记住你了快速选择。。。!
View Code
于是想写写"快速选择算法"。。。结果啊。。。
调了1h。。。欧我去。。。至于么,已经蒟蒻到这种程度了?
反正我是记住你了快速选择。。。!
/************************************************************** Problem: 1753 User: rausen Language: C++ Result: Accepted Time:8 ms Memory:844 kb ****************************************************************/ #include <cstdio> #include <algorithm> using namespace std; const int N = 10005; int n, a ; inline int read(){ int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9'){ x = x * 10 + ch - '0'; ch = getchar(); } return x; } int find(int l, int r, int rank){ int i = l, j = r + 1; int x = a[l]; while (1){ while (a[++i] < x); while (x < a[--j]); if (i > j) break; swap(a[i], a[j]); } swap(a[l], a[j]); if (j - l + 1 == rank) return a[j]; else if (j - l + 1 > rank) return find(l, j - 1, rank); else return find(j + 1, r, rank - (j - l + 1)); } int main(){ n = read(); int i; for (i = 1; i <= n; ++i) a[i] = read(); printf("%d\r\n", find(1, n, (n + 1) >> 1)); return 0; }
View Code
相关文章推荐
- BZOJ1753: [Usaco2005 qua]Who's in the Middle
- bzoj1753 [Usaco2005 qua]Who's in the Middle
- bzoj 1753: [Usaco2005 qua]Who's in the Middle【排序】
- 1753: [Usaco2005 qua]Who's in the Middle
- bzoj1753 [Usaco2005 qua]Who's in the Middle
- bzoj1753 [Usaco2005 qua]Who's in the Middle
- 1753: [Usaco2005 qua]Who's in the Middle (快速排序)
- BZOJ 1753 Who's in the Middle
- bzoj1752 [Usaco2005 qua]Til the Cows Come Home
- bzoj1752 [Usaco2005 qua]Til the Cows Come Home
- POJ 2388 Who's in the Middle
- poj 2388 Who's in the Middle
- bzoj1754 [Usaco2005 qua]Bull Math
- poj 2388 Who's in the Middle(快速排序求中位数)
- poj 2388 Who's in the Middle
- Hdu 1157 Who's in the Middle
- bzoj1754 [Usaco2005 qua]Bull Math
- POJ 2388 Who's in the Middle
- 第K小数 uva 10041 - Vito's Family poj 2388 Who's in the Middle
- HDU 1157 Who's in the Middle