原题链接: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. Oracle 自定义函数Function

    示例代码: CREATE OR REPLACE  FUNCTION "MY_DATABASE"."F_GET_USER_COUNT_BY_DEPART" ( D ...

  2. 简单的TCPIP 客户端 服务器

    // soClient.cpp : Defines the entry point for the console application. // #include "stdafx.h&qu ...

  3. python urllib urllib2

    区别 1) urllib2可以接受一个Request类的实例来设置URL请求的headers,urllib仅可以接受URL.这意味着,用urllib时不可以伪装User Agent字符串等. 2) u ...

  4. rel="stylesheet" 描述

    <link type="text/css" rel="stylesheet" href="css/style.css"/> re ...

  5. Android Malware Analysis

    A friend of mine asked me help him to examine his Android 5.0 smartphone. He did not say what's wron ...

  6. wordpress代理设置

    打开wp-config.php,在页首加上以下语句: define('WP_PROXY_HOST', '192.168.84.101'); define('WP_PROXY_PORT', '8080' ...

  7. POJ C程序设计进阶 编程题#3: 发票统计

    来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 有一个小型的报账系统,它有如 ...

  8. 学习笔记 - 数据绑定之knockout

    参考: http://www.cnblogs.com/TomXu/archive/2011/11/21/2257154.html http://knockoutjs.com/documentation ...

  9. 在Spark中使用Kryo序列化

    spark序列化  对于优化<网络性能>极为重要,将RDD以序列化格式来保存减少内存占用. spark.serializer=org.apache.spark.serializer.Jav ...

  10. 用户View,五大布局

    1.LinearLayout 线性布局 android:orientation="horizontal" 制定线性布局的排列方式 水平 horizontal 垂直 vertical ...