• Vijos1647 不差钱


    题目链接:https://vijos.org/p/1647

    Orz此题的神背景和输出……

    笨人自有笨办法:代码中price[i]表示第i号菜的价格,soldout[i]表示价格为i的菜被标记为卖完的种类数。

    询问时用一个pair<int,int>同时返回第i贵的菜的种类数与价格,将第i贵的菜的种类数与被标记为卖完的该价格的菜的种类数比较(好拗口啊),若前者减后者大于等于1则说明有否则没有。

    另外输出要严格按照题目中所说优先级,前者优先级大于后者。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <ctime>
     6 #define rep(i,l,r) for(int i=l; i<=r; i++)
     7 #define clr(x,y) memset(x,y,sizeof(x))
     8 using namespace std;
     9 typedef long long ll;
    10 typedef pair<int,int> pii;
    11 const int INF = 0x3f3f3f3f;
    12 const int maxn = 100010;
    13 struct node{
    14     int l,r,v,w,rnd,size;
    15 }t[maxn];
    16 int n,high,p,cnt=0,tot=0,root=0,invalidcnt=0,price[maxn],soldout[1000010];
    17 inline int read(){
    18     int ans = 0, f = 1;
    19     char c = getchar();
    20     while (!isdigit(c)){
    21         if (c == '-') f = -1;
    22         c = getchar();
    23     }
    24     while (isdigit(c)){
    25         ans = ans * 10 + c - '0';
    26         c = getchar();
    27     }
    28     return ans * f;
    29 }
    30 void update(int w){
    31     t[w].size = t[t[w].l].size + t[t[w].r].size + t[w].w;
    32 }
    33 void rotl(int &w){
    34     int k = t[w].r; t[w].r = t[k].l; t[k].l = w;
    35     update(w); update(k); w = k;
    36 }
    37 void rotr(int &w){
    38     int k = t[w].l; t[w].l = t[k].r; t[k].r = w;
    39     update(w); update(k); w = k;
    40 }
    41 void insert(int x,int &w){
    42     if (!w){
    43         w = ++cnt; t[w].v = x; t[w].w = t[w].size = 1;
    44         t[w].rnd = rand();
    45         t[w].l = t[w].r = 0;
    46         return;
    47     }
    48     t[w].size++;
    49     if (t[w].v == x) t[w].w++;
    50     else if (x < t[w].v){
    51         insert(x,t[w].l);
    52         if (t[t[w].l].rnd < t[w].rnd) rotr(w);
    53     }
    54     else{
    55         insert(x,t[w].r);
    56         if (t[t[w].r].rnd < t[w].rnd) rotl(w);
    57     }
    58 }
    59 pii query(int x,int w){
    60     if (!w) return make_pair(0,0);
    61     if (x <= t[t[w].l].size) return query(x,t[w].l);
    62     else if (x > t[t[w].l].size + t[w].w) return query(x-t[t[w].l].size-t[w].w,t[w].r);
    63     else return make_pair(t[w].w,t[w].v);
    64 }
    65 int main(){
    66     srand(time(0));
    67     high = read();
    68     while(1){
    69         p = read();
    70         if (p == 1){
    71             n = read(); price[++tot] = n;
    72             if (n > high) invalidcnt++;
    73             else insert(n,root);
    74         }
    75         else if (p == 2){
    76             n = read();
    77             soldout[price[n]]++;
    78         }
    79         else if (p == 3){
    80             n = read();
    81             if (n <= invalidcnt) printf("Dui bu qi,Mei you.
    ");
    82             else{
    83                 pii now = query(cnt-n+invalidcnt+1,root);
    84                 if (now.first - soldout[now.second] >= 1) printf("You. %d Yuan.
    ",now.second);
    85                 else printf("Mei you. Zhe ge ke yi you. Zhe ge zhen mei you!
    ");
    86             }
    87         }
    88         else break;
    89     }
    90     return 0;
    91 }
    View Code
  • 相关阅读:
    十大开源CRM
    EL表达式【转】
    zk调用js(转)
    MVC4学习笔记(三) 数据验证设计
    MVC4学习笔记(一) 认识MVC
    MVC4学习笔记(四) MVC界面设计
    hibernate介绍
    如何在oracle中导入dmp数据库文件
    JS的delete操作
    使用JavaScript给Html元素加边框
  • 原文地址:https://www.cnblogs.com/jimzeng/p/vijos1647.html
Copyright © 2020-2023  润新知