原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2648

纯暴力的方法T_T。。。

如下:

 #include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include<algorithm>
typedef char State[];
char *target = "memory";
const int Max_N = ;
struct Node{
State name;
int v, s;
Node *ch[];
inline void
set(int _v = , char *src = "", int _s = ,Node *p = NULL){
ch[] = ch[] = p;
v = _v, s = _s, 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 SizeBalanceTree{
Node *tail, *null, *root;
Node stack[Max_N];
void init(){
tail = &stack[];
null = tail++;
null->set();
root = null;
}
inline Node *newNode(char *name, int v){
Node *p = tail++;
p->set(v, name, , null);
return p;
}
inline void rotate(Node* &x, int d){
Node *k = x->ch[!d];
x->ch[!d] = k->ch[d];
k->ch[d] = x;
k->s = x->s;
x->push_up();
x = k;
}
inline void Maintain(Node* &x, int d){
if (x->ch[d] == null) return;
if (x->ch[d]->ch[d]->s > x->ch[!d]->s){
rotate(x, !d);
} else if (x->ch[d]->ch[!d]->s > x->ch[!d]->s){
rotate(x->ch[d], d), rotate(x, !d);
} else {
return;
}
Maintain(x, ), Maintain(x, );
}
inline void insert(Node* &x, char *name, int v){
if (x == null){
x = newNode(name, v);
return;
} else {
x->s++;
int d = x->cmp(name);
insert(x->ch[d], name, v);
x->push_up();
Maintain(x, d);
}
}
inline Node *Modify(Node *x, char *name){
if (x == null) return null;
int d = x->cmp(name);
if (- == d) return x;
else return Modify(x->ch[d], name);
}
inline void insert(char *str, int v = ){
insert(root, str, v);
return;
}
inline void Modify(char *str, int v){
Node* ret = Modify(root, str);
ret->v += v;
}
inline void dfs(Node *x, int v, int &ans){
if (x != null){
dfs(x->ch[], v, ans);
if (x->v > v) ans++;
dfs(x->ch[], v, ans);
}
}
inline void query(){
int cnt = , ans = ;
int v = Modify(root, target)->v;
dfs(root, v, ans);
printf("%d\n", ans + );
}
}sbt;
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)){
sbt.init();
for (int i = ; i < n; i++){
scanf("%s", buf);
sbt.insert(buf);
}
scanf("%d", &m);
while (m--){
for (int i = ; i < n; i++){
scanf("%d %s", &val, buf);
sbt.Modify(buf, val);
}
sbt.query();
}
}
return ;
}

hdu 2648 Shopping的更多相关文章

  1. HDU 1170 Shopping Offers 离散+状态压缩+完全背包

    题目链接: http://poj.org/problem?id=1170 Shopping Offers Time Limit: 1000MSMemory Limit: 10000K 问题描述 In ...

  2. map的使用-Hdu 2648

    Shopping Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. HDU 2648(搜索题,哈希表)

    #include<iostream> #include<map> #include<string> #include<cstring> #include ...

  4. 第一周训练 | STL和基本数据结构

    A - 圆桌问题: HDU - 4841 #include<iostream> #include<vector> #include<stdio.h> #includ ...

  5. Hash算法入门指南(聊点不一样的算法人生)

    前言 很多人到现在为止都总是问我算法该怎么学啊,数据结构好难啊怎么的,学习难度被莫名的夸大了,其实不然.对于一个学计算机相关专业的人都知道,数据结构是大学的一门必修课,数据结构与算法是基础,却常常容易 ...

  6. POJ 3831 &amp; HDU 3264 Open-air shopping malls(几何)

    题目链接: POJ:id=3831" target="_blank">http://poj.org/problem?id=3831 HDU:http://acm.h ...

  7. 背包系列练习及总结(hud 2602 && hdu 2844 Coins && hdu 2159 && poj 1170 Shopping Offers && hdu 3092 Least common multiple && poj 1015 Jury Compromise)

    作为一个oier,以及大学acm党背包是必不可少的一部分.好久没做背包类动规了.久违地练习下-.- dd__engi的背包九讲:http://love-oriented.com/pack/ 鸣谢htt ...

  8. HDU 3264 Open-air shopping malls (计算几何-圆相交面积)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...

  9. hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分 圆相交面积 难度:1

    Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...

随机推荐

  1. Java导出数据为EXCEL的两种方式JXL和POI

    JXL和POI导出数据方式的比较 POI支持excel2003和2007,而jxl只支持excel2003. 下面为测试代码: public class TestCondition { /** * 生 ...

  2. iOS百度地图探索

    新建工程后,几项准备: 1.工程中一个文件设为.mm后缀 2.在Xcode的Project -> Edit Active Target -> Build -> Linking -&g ...

  3. Duilib学习笔记《04》— 窗体显示

    在前面已经了解了duilib控件以及界面布局相关内容,接下来就要考虑该如何将xml中描述的布局通过界面展现出来.实际上在 Duilib学习笔记<01> 中我们已经简单提到过基本的流程及元素 ...

  4. APUE第五章:标准IO库

    5.2流和file对象 #include <wchar.h> int fwide(FILE *fp, int mode); Returns: positive if stream is w ...

  5. 从汇编层面深度剖析C++虚函数

    文章出处:http://blog.csdn.net/linyt/article/details/6336762 虚函数是C++语言实现运行时多态的唯一手段,因此掌握C++虚函数也成为C++程序员是否合 ...

  6. SQL Server 数据库设计

    一.数据库设计的必要性 在实际的软件项目中,如果系统中需要存储的数据量比较大,需要设计的表比较多,表与表之间的关系比较复杂,那我们就需要进行规范的数据库设置.如果不经过数据库的设计,我们构建的数据库不 ...

  7. boost::asio 使用实例

    #include <iostream> #include <boost/asio.hpp> using namespace std; using namespace boost ...

  8. Save a bricked Samsung Note 3 and do extraction

    The case scenario was about bank robery and the suspect threw his Samsung Note 3 into the river. For ...

  9. css3mediaquery移动端网页字体适应屏幕代码

    @media screen and (min-width:320px) and (max-width:321px) { html { font-size: 62.5%; } } @media scre ...

  10. A Neural Probabilistic Language Model

    A Neural Probabilistic Language Model,这篇论文是Begio等人在2003年发表的,可以说是词表示的鼻祖.在这里给出简要的译文 A Neural Probabili ...