栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2243 Binary Search Heap C...

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2243 Binary Search Heap C...

#include <cstdio>#include <cstring>#include <cassert>#include <algorithm>#include <cstdlib>#include <string>#include <vector>using namespace std;typedef pair<string, int> psi;typedef vector<psi> vpsi;struct Node {Node *child[2], *parent;string key; int fix;Node(string _key, int _fix) {child[0] = child[1] = parent = NULL;key = _key;fix = _fix;}};struct Cartesian {Node *root, *back;Cartesian() {root = back = NULL;}void rotate(Node *rt, bool left){bool right = !left;Node *p = rt->child[right];p->parent = rt->parent;if (p->child[left]) p->child[left]->parent = rt;rt->child[right] = p->child[left];rt->parent = p-> child[left];p->child[left] = rt;}void pushBack(Node *x) {Node *p = back;while (p && p->fix < x->fix) p = p->parent;if (p) {if (p->child[false]) p->child[false]->parent = x;x->child[true] = p->child[false];x->parent = p;p->child[false] = x;} else {if (root) root->parent = x;x->child[true] = root;root = x;}back = x;}void print(Node *T) {if (!T) return ;putchar('(');print(T->child[true]);printf("%s/%d", T->key.c_str(), T->fix);print(T->child[false]);putchar(')');}}cart;void deal(int n) {cart = Cartesian();char buf[100];vpsi tmp;while (n--){scanf("%s", buf);int p = 0, key;while (buf[p] != '/') p++;buf[p] = 0;sscanf(&buf[p + 1], "%d", &key);tmp.push_back(make_pair(buf, key));}sort(tmp.begin(), tmp.end());int size = tmp.size();for (int i = 0; i < size; i++) {Node *temp = new Node(tmp[i].first, tmp[i].second);cart.pushBack(temp);}cart.print(cart.root);puts("");}int main(){int n;while (~scanf("%d", &n) && n){deal(n);}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/376170.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号