hdu 2648 Shopping
原题链接: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的更多相关文章
- HDU 1170 Shopping Offers 离散+状态压缩+完全背包
题目链接: http://poj.org/problem?id=1170 Shopping Offers Time Limit: 1000MSMemory Limit: 10000K 问题描述 In ...
- map的使用-Hdu 2648
Shopping Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2648(搜索题,哈希表)
#include<iostream> #include<map> #include<string> #include<cstring> #include ...
- 第一周训练 | STL和基本数据结构
A - 圆桌问题: HDU - 4841 #include<iostream> #include<vector> #include<stdio.h> #includ ...
- Hash算法入门指南(聊点不一样的算法人生)
前言 很多人到现在为止都总是问我算法该怎么学啊,数据结构好难啊怎么的,学习难度被莫名的夸大了,其实不然.对于一个学计算机相关专业的人都知道,数据结构是大学的一门必修课,数据结构与算法是基础,却常常容易 ...
- POJ 3831 & HDU 3264 Open-air shopping malls(几何)
题目链接: POJ:id=3831" target="_blank">http://poj.org/problem?id=3831 HDU:http://acm.h ...
- 背包系列练习及总结(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 ...
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...
- 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 ...
随机推荐
- MBProgressHUD 扩展加载动画
效果图: 设计给了一个组的图片,但是由于是透明的背景,会产生卡顿,其实只要两张图片就可以了 创建一个 MBProgressHUD 分类 增加方法 + (MB_INSTANCETYPE)myShowHU ...
- Visual Studio 2010 C++ 工程文件解读
在 VS2010 中,C++ 的工程文件已经和 2005 / 2008 有了很大的不同,而是完全采用 MSBUILD 的属性方式进行表达,并且可以让用户通过一次性的配置而对所有的属性进行自定义: 根据 ...
- Android——Runtime类中的freeMemory,totalMemory,maxMemory等几个方法
maxMemory() 这个方法返回的是java虚拟机(这个进程)能构从操作系统那里挖到的最大的内存,以字节为单位,如果在运行java程序的时 候,没有添加-Xmx参数,那么就是64兆,也就是说max ...
- android studio首次运行出错
转载2015-10-24 16:28:15 标签:androidstudioandroidstudio无法启androidstudio1.4无法 Internal error. Please repo ...
- APUE第一章_课后习题
/* 未完成的:1.5 不过在下文中已经给出了解答. */ 1.1 在系统上查证,除根目录外,目录.和..是不同的 ans:这个很容易,用vim打开.和..就可以看到区别. 1.2 分析程序清单1-4 ...
- javascript ES5 Object对象
原文:http://javascript.ruanyifeng.com/stdlib/object.html 目录 概述 Object对象的方法 Object() Object.keys(),Obje ...
- 盒子的padding不影响总的大小css代码
-moz-box-sizing: border-box; /*Firefox3.5+*/-webkit-box-sizing: border-box; /*Safari3.2+*/-o-box-siz ...
- MySQL的存储引擎整理
01.MyISAM MySQL 5.0 以前的默认存储引擎.MyISAM 不支持事务.也不支持外键,其优势是访问的速度快,对事务完整性没有要求或者以SELECT.INSERT 为主的应用基本上都可以使 ...
- openstack简介
OpenStack是一个开源的云计算管理平台项目,由几个主要的组件组合起来完成具体工作.OpenStack支持几乎所有类型的云环境,项目目标是提供实施简单.可大规模扩展.丰富.标准统一的云计算管理平台 ...
- POJ C程序设计进阶 编程题#5:细菌分组实验
编程题#5:细菌实验分组 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 有 ...