pku2153 Rank List
2013-05-29 10:18
232 查看
http://poj.org/problem?id=2153
二分查找
二分查找
#include <stdio.h> #include <iostream> #include <string> #include <string.h> #include <map> using namespace std; int n, m; map<string, int> map1; int count1[10010] = {0}; int sort1[10010]; string ctos(char s[]) { int i; string r; for(i=0; s[i]; i++) { r += s[i]; } return r; } int cmp(const void *a, const void *b) { return *((int *)b) - *((int *)a); } int bs(int l, int h, int v) { int m; while ( l < h ) { m = ( l + h ) >> 1; if (sort1[m] > v) { l=m+1; } else { h=m; } } return l; } int main() { int i, j, x, y, k; char s[33] = "\0"; string s1; scanf("%d%*c", &n); for(i=1; i<=n; i++) { gets(s); s1 = ctos(s); map1.insert(make_pair(s1, i)); memset(s, 0, sizeof(s)); } scanf("%d", &m); for(i=1; i<=m; i++) { for(j=1; j<=n; j++) { scanf("%d%*c", &x); gets(s); s1 = ctos(s); y = map1[s1]; //printf("%d %d\n", x, y); count1[y] += x; } for(j=1; j<=n; j++) { sort1[j] = count1[j]; } k = sort1[map1["Li Ming"]]; qsort(sort1+1, n, sizeof(sort1[0]), cmp); printf("%d\n", bs(1, n+1, k)); } return 0; }
相关文章推荐
- poj2153 Rank List
- poj 2153 Rank List
- poj 2153 Rank List
- poj 2153 Rank List
- poj 2153 Rank List
- Rank List - POJ 2153 map
- poj 2153 Rank List
- Poj 2153 Rank List
- POJ2153-Rank List
- POJ 2153 Rank List
- pku 2153 Rank List
- PKU 2153
- pku 3863 Business Center 二分 或 扩展欧几里得
- pku 3114 Countries in War tarjan缩点+spfa求最短路
- PKU 1088 滑雪
- pku 2195 Going Home KM最小权匹配问题
- pku1178: Camelot
- [强联通分量_tarjan] PKU 1236 Network of Schools
- pku2182: Lost Cows
- PKU 2528 Mayor's posters