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 ...
随机推荐
- 【PL/SQL练习】显式游标
cursor --------需要用户先定义,在select时,可以用于处理多行记录 1.declare 声明一个游标 2.open cursor (隐式游标自动open) 3.fetch curs ...
- notepad++ tab键用空格缩进
从工作那天开始到现在,写python代码一直用notepad++来写,尝试几次都改不回eclipse.o(╯□╰)o python脚本中,如果用制表符缩进,经常会报错,必须改用空格缩进代替. 之前设置 ...
- Mysql-5.7.10启动失败 。
Mysql-5.7.10在免安装后启动服务失败. 查看日志得到如下: 2016-02-19T03:41:05.557095Z 0 [Warning] TIMESTAMP with implicit D ...
- WP8_访问ListBox中的Item项中的某个元素
How to access a Control placed inside ListBox ItemTemplate in WP7(转) In this post I am going to talk ...
- std::cout彩色输出
Mac OS效果 Windows 效果 想写这个东西其实是因为最近要写个命令行的工具,但是有个问题是什么呢?就是传统的那个黑漆漆的窗口看起来很蛋疼.并且完全看不到重点,于是就想起 来这么一个东西.相对 ...
- C# 通过this关键字来扩展方法
好处:不需要继承,对现有类型进行扩展 public static class ExtString { public static string myTest(this String str) { re ...
- CentOS6.5安装readline时报错:/usr/bin/ld : cannot find -lncurses
CentOS6.5安装readline时报错:/usr/bin/ld : cannot find -lncurses 解决方法: 安装ncurses-devel,输入命令: #yum install ...
- select 语句占位符
对于已预备的语句,可以使用位置保持符.以下语句将从tb1表中返回一行: mysql> SET @a=1; mysql> PREPARE STMT FROM "SELECT * F ...
- PHP-POSIX正则表达式函数
1.ereg() 格式:ereg("条件",<原始字符串>) ereg()查找字符串,是严格区分大小写的 <?php $string="apples a ...
- 15)Java &和&&
&,双目运算符:将两个表达式的值按二进制位展开,对应的位(bit)按值进行"与"运算,结果保留在该位上- 比如170&204对应二进制就是 1010101 ...