原题链接:http://poj.org/problem?id=2153 
简单题,map,平衡树均可。。 
map:

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<map>
using std::cin;
using std::map;
using std::string;
map<string, int> ret;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
string buf;
int n, m, v, tmp;
while (cin >> n) {
getchar();
for (int i = ; i < n; i++) {
getline(cin, buf);
ret[buf] = ;
}
cin >> m;
while (m--) {
int ans = ;
for (int i = ; i < n; i++) {
cin >> v;
getchar();
getline(cin, buf);
ret[buf] += v;
}
tmp = ret["Li Ming"];
map<string, int>::iterator ite;
for (ite = ret.begin(); ite != ret.end(); ++ite) {
if (ite->second > tmp) ans++;
}
printf("%d\n", ans + );
}
ret.clear();
}
return ;
}

平衡树:

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
typedef char State[];
char *target = "Li Ming";
const int Max_N = ;
struct Node {
State name;
int data, s;
bool color;
Node *fa, *ch[];
inline void set(int _v, char *src, bool _color, int i, Node *p) {
data = _v, color = _color, s = i;
fa = ch[] = ch[] = p;
strcpy(name, src);
}
inline void push_up() {
s = ch[]->s + ch[]->s + ;
}
inline int cmp(char *src) const {
if ( == strcmp(src, name)) return -;
else if (- == strcmp(src, name)) return ;
return ;
}
};
struct RedBlackTree {
Node *root, *null;
Node stack[Max_N], *tail;
void init() {
tail = &stack[];
null = tail++;
null->set(, "", , , NULL);
root = null;
}
inline Node *newNode(char *name, int v) {
Node *p = tail++;
p->set(v, name, , , null);
return p;
}
inline void rotate(Node* &x, bool d) {
Node *y = x->ch[!d];
x->ch[!d] = y->ch[d];
if (y->ch[d] != null) y->ch[d]->fa = x;
y->fa = x->fa;
if (x->fa == null) root = y;
else x->fa->ch[x->fa->ch[] != x] = y;
y->ch[d] = x;
x->fa = y;
y->s = x->s;
x->push_up();
}
inline void insert(char *name, int v = ) {
int d = ;
Node *x = root, *y = null;
while (x->s) {
x->s++;
d = x->cmp(name);
y = x, x = x->ch[d];
}
x = newNode(name, v);
if (y != null) { d = x->cmp(y->name), y->ch[!d] = x; }
else root = x;
x->fa = y;
insert_fix(x);
}
inline void insert_fix(Node* &x) {
while (x->fa->color){
Node *par = x->fa, *Gp = par->fa;
bool d = par == Gp->ch[];
Node *uncle = Gp->ch[d];
if (uncle->color) {
par->color = uncle->color = ;
Gp->color = ;
x = Gp;
} else if (x == par->ch[d]) {
rotate(x = par, !d);
} else {
Gp->color = ;
par->color = ;
rotate(Gp, d);
}
}
root->color = ;
}
inline Node *find(Node *x, char *name) {
while (x->s) {
int d = x->cmp(name);
if (- == d) break;
x = x->ch[d];
}
return x;
}
inline void Modify(char *str, int v) {
Node* ret = find(root, str);
ret->data += v;
}
inline void dfs(Node *x, int v, int &ans) {
if (x != null){
dfs(x->ch[], v, ans);
if (x->data > v) ans++;
dfs(x->ch[], v, ans);
}
}
inline void query() {
int cnt = , ans = ;
int v = find(root, target)->data;
dfs(root, v, ans);
printf("%d\n", ans + );
}
}rbt;
int main(){
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
char buf[];
int n, m, val;
while (~scanf("%d\n", &n)) {
rbt.init();
for (int i = ; i < n; i++) {
gets(buf);
rbt.insert(buf);
}
scanf("%d\n", &m);
while (m--) {
for (int i = ; i < n; i++) {
gets(buf);
sscanf(buf, "%d", &val);
rbt.Modify(strchr(buf, ' ') + , val);
}
rbt.query();
}
}
return ;
}

poj 2153 Rank List的更多相关文章

  1. poj 2153 Rank List(查找,Map)

    题目链接:http://poj.org/problem?id=2153 思路分析: 判断Li Ming的成绩排名,需要在所有的数据章查找成绩比其高的人的数目,为查找问题. 查找问题可以使用Hash表, ...

  2. POJ 2153 Rank List (map映射)

    水题,竟然花了那么多时间...主要是不知道为什么,明明在本机上编译过去了,但是用c++提交却编译错误...最后用g++提交AC 题意:给出n个学生的名字,然后给出m个测验. 每个测验给出n个学生的分数 ...

  3. 成绩累加排名,poj(2153)

    题目链接:http://poj.org/problem?id=2153 解题报告: 注意map中的string,因此要将char[]转换为string型. #include <iostream& ...

  4. poj 2153

    题意:题目还是很简单的,就是求Li Ming 在班上的排名,而且成绩是相加的. 思路:用map就行.不然好像用qsort+二分也可以,不过我在那里碰到了一些状况,然后就没用这种方法了,简单的map就可 ...

  5. POJ 2153 stl

    #include<iostream> #include<map> #include<string> using namespace std; int main() ...

  6. POJ - 1245 Programmer, Rank Thyself

    POJ - 1245 Programmer, Rank Thyself Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d  ...

  7. POJ 2379 ACM Rank Table(排序)

    题很水,数据注意一下四点即可: 1.有些team会在一道题AC了之后还提交,这个时候只需要算第一次ac的时间以及这之前的wa,之后的全部忽略.2.如果一道题没有ac,那么在计算时间时不应该加上它的wa ...

  8. 字符串专题:KMP POJ 3561

    http://poj.org/problem?id=3461 KMP这里讲的不错next的求法值得借鉴 http://blog.sina.com.cn/s/blog_70bab9230101g0qv. ...

  9. poj 并查集

    http://poj.org/problem?id=1611 水题 题意:就是找一共有多少个人感染了,0是感染学生的编号. #include <stdio.h> #include < ...

随机推荐

  1. SDUT 3347 数据结构实验之数组三:快速转置

    数据结构实验之数组三:快速转置 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 转置运算是一 ...

  2. 将Excel中数据导入数据库(一)

    在工作中经常要将Excel中数据导入数据库,这里介绍一种方法. 假如Excel中的数据如下: 数据库建表如下: 其中Id为自增字段: Excel中数据导入数据库帮助类如下: using System; ...

  3. Decks

    Now that we have Card objects, the next step is to define a class to represent decks. Since a deck i ...

  4. 数据库中GUID的生成

    GUID, 即Globally Unique Identifier(全球唯一标识符) 也称作 UUID(Universally Unique IDentifier) . GUID是一个通过特定算法产生 ...

  5. MySQL数据库获取汉字拼音的首字母函数

    需求简介:最近的一个项目,想实现如下图所示的显示效果.很明显,如果能够获取对应的汉字词组的拼音首字母就可以实现了,如果是固定的几个汉字,人为的拼一下就可以了,不过项目中有多处功能是需要这个效果的,并且 ...

  6. Weblogic发布小问题——The root element weblogic-web-app is missing in the descriptor file

    前几天发布项目遇到这样一个小错误,在此记录一下,以便加深一点印象,下次好解决类似的问题! (对应的应用服务器是WebLogic Server 版本: 10.3.6.0,应用是以文件夹的形式发在服务器的 ...

  7. 洛谷P2751 [USACO4.2]工序安排Job Processing

    P2751 [USACO4.2]工序安排Job Processing 18通过 78提交 题目提供者该用户不存在 标签 难度普及+/提高 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 一家工 ...

  8. 洛谷P1530 分数化小数 Fractions to Decimals

    P1530 分数化小数 Fractions to Decimals 103通过 348提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目 ...

  9. ASPxGridView中如何对主从表绑定数据

    注:在从表的aspxgridview中的(OnDataBinding()事件中绑定数据)-----代码如下 //绑定属性值表protected void grid2_sonTable_DataBind ...

  10. JS 和 CSS 的位置对其他资源加载顺序的影响

    JS 和 CSS 在页面中的位置,会影响其他资源(指 img 等非 js 和 css 资源)的加载顺序,究其原因,有三个值得注意的点: JS 有可能会修改 DOM. 典型的,可能会有 document ...