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 ...
随机推荐
- 将Excel中数据导入数据库(三)
上篇文章将Excel中数据导入数据库时,将从Excel读入的数据均转换成了数据库相应字段的类型,其实这是没有必要的,因为对于数据库各种类型的插入,均可以字符串格式插入.比如表WQ_SWMSAR_A字段 ...
- 使用ngin的静态文件下载
1,主配置文件nginx.xml #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error. ...
- Oracle 学习系列之一(表空间与表结构)
create tablespace user3 datafile 'e:\test\user3_data.dbf' size 20M --表空间初始大小为: 20Mautoextend on next ...
- EnCase v.s. FTK - find out Chinese characters writing in different direction
A friend of mine said to me that she could fool those forensic tools easily by changing writing dire ...
- Completely change MACE timestamps?
Hi, One of my friends Sandy asked me about the possibility of completely change MACE timestamps. As ...
- Android 按键式事件
1. package com.fish.helloworld; import android.app.Activity; import android.graphics.Color; import a ...
- ASP.NET MVC SignalR
本系列博文主要介绍了 ASP.NET SignalR 的相关知识与开发,参考来源为<ASP.NET SignalR 编程实践>. 目录: SignalR背景 SignalR概述
- .NET常用类库知识总结
常用类库之.NET中的字符串 字符串的特性 1.不可变性 由于字符串是不可变的的,每次修改字符串,都是创建了一个单独字符串副本(拷贝了一个字符串副本).之所以发生改变只是因为指向了一块新 ...
- 鸟哥笔记:postfix的一些重要配置文件
postfix的一些主要配置文件都放在/etc/postfix/目录下,其中几个重要的配置文件有main.cf.master.cgf.access和aliases文件. /etc/postfic/ma ...
- DPDK内存管理-----(一)初始化
1 前言 DPDK通过使用hugetlbfs,减少CPU TLB表的Miss次数,提高性能. 2 初始化 DPDK的内存初始化工作,主要是将hugetlbfs的配置的大内存页,根据其映射的物理地址是否 ...