题意:供应商提供n块价格为c的冰淇淋,一个学生想买n块冰淇淋,手中的钱数总共有t元,为了不让买n块冰淇淋所花费的钱数不超过t元,先尽可能卖给这个学生便宜的冰淇淋。

如果这个学生不能买到所需要的冰淇淋则输出“UNHAPPY”,能则输出“HAPPY”。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 200000
using namespace std; long long x[maxn];
struct node1
{
char str[];
int n;
long long w;
}p[maxn];
struct node
{
int l,r;
long long num;
long long sum;
int flag;
}tree[maxn*]; void up(int i)
{
if(tree[i].l==tree[i].r) return ;
tree[i].sum=tree[i<<].sum+tree[i<<|].sum;
tree[i].num=tree[i<<].num+tree[i<<|].num;
}
void down(int i)
{
if(tree[i].l==tree[i].r) return ;
if(tree[i].flag!=-)
{
tree[i<<].sum=tree[i<<|].sum=;
tree[i<<].num=tree[i<<|].num=;
tree[i<<].flag=tree[i<<|].flag=;
tree[i].flag=-;
}
} void build(int i,int l,int r)
{
tree[i].l=l; tree[i].r=r;
tree[i].num=tree[i].sum=;
tree[i].flag=-;
if(l==r) return ;
int mid=(l+r)>>;
build(i<<,l,mid);
build(i<<|,mid+,r);
} void deal(int i,int n,int c)
{
tree[i].sum+=(long long)c*n;
tree[i].num+=n;
if(x[tree[i].l]==c&&x[tree[i].r]==c) return ;
down(i);
if(c<=x[tree[i<<].r]) deal(i<<,n,c);
else deal(i<<|,n,c);
} long long search1(int i,int n)
{
if(tree[i].l==tree[i].r)
{
return (long long)n*x[tree[i].l];
}
down(i);
if(tree[i<<].num>=n) return search1(i<<,n);
else
return tree[i<<].sum+search1(i<<|,n-tree[i<<].num);
} void change(int i,int n)
{
if(tree[i].l==tree[i].r)
{
tree[i].num-=n;
tree[i].sum=tree[i].num*x[tree[i].l];
return ;
}
down(i);
if(tree[i<<].num>=n)
{
change(i<<,n);
}
else
{
change(i<<|,n-tree[i<<].num);
tree[i<<].num=;
tree[i<<].sum=;
tree[i<<].flag=;
}
up(i);
}
int main()
{
int cnt=,t1=;
while(scanf("%s %d%I64d",p[cnt].str,&p[cnt].n,&p[cnt].w)==)
{
if(p[cnt].str[]=='A')
{
x[t1++]=p[cnt].w;
}
cnt++;
}
sort(x,x+t1);
t1=unique(x,x+t1)-x;
build(,,t1-);
for(int i=; i<cnt; i++)
{
if(p[i].str[]=='A')
{
deal(,p[i].n,p[i].w);
}
else
{
if(tree[].num<p[i].n) printf("UNHAPPY\n");
else
{
if(search1(,p[i].n)>p[i].w) printf("UNHAPPY\n");
else
{
printf("HAPPY\n");
change(,p[i].n);
}
}
}
}
return ;
}

sgu Ice-cream Tycoon的更多相关文章

  1. HackerRank Ice Cream Parlor

    传送门 Ice Cream Parlor Authored by dheeraj on Mar 21 2013 Problem Statement Sunny and Johnny together ...

  2. How to Implement Bluetooth Low Energy (BLE) in Ice Cream Sandwich

    ShareThis - By Vikas Verma Bluetooth low energy (BLE) is a feature of Bluetooth 4.0 wireless radio t ...

  3. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  4. Ice Cream Tower

    2017-08-18 21:53:38 writer:pprp 题意如下: Problem D. Ice Cream Tower Input file: Standard Input Output f ...

  5. 2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 二分+贪心

    /** 题目:2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 链接:http://codeforces.com/gym/101194 题意:给n个木块,堆 ...

  6. E. Sonya and Ice Cream(开拓思维)

    E. Sonya and Ice Cream time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  7. 【HackerRank】Ice Cream Parlor

    Sunny and Johnny together have M dollars which they intend to use at the ice cream parlour. Among N ...

  8. 【Codeforces Round #411 (Div. 1)】Codeforces 804C Ice cream coloring (DFS)

    传送门 分析 这道题做了好长时间,题意就很难理解. 我们注意到这句话Vertices which have the i-th (1 ≤ i ≤ m) type of ice cream form a ...

  9. 【dfs+理解题意+构造】【待重做】codeforces E. Ice cream coloring

    http://codeforces.com/contest/805/problem/E [题意] 染色数是很好确定,最少染色数是max(si)(最小为1,即使所有的si都为0,这样是单节点树形成的森林 ...

  10. codeforces 686A A. Free Ice Cream(水题)

    题目链接: A. Free Ice Cream //#include <bits/stdc++.h> #include <vector> #include <iostre ...

随机推荐

  1. MySQL 学习笔记 (范式)

    范式基本就是不要有重复的数据,表和表之间都是用主键和外键来联系 表的关系通常分3中 1 对 1 1 对 多 多 对 多 多 对 多 是用另一个表来实现的,这个表记入了a 表和 b表之间多对多的联系主键

  2. 转:linux shell 数组建立及使用技巧

    linux shell在编程方面比windows 批处理强大太多,无论是在循环.运算.已经数据类型方面都是不能比较的. 下面是个人在使用时候,对它在数组方面一些操作进行的总结. 1.数组定义 [che ...

  3. 【转】win7与ubuntu双系统,删除ubuntu后,启动错误error:no such partition grub rescue的修复--不错

    原文网址:http://blog.sina.com.cn/s/blog_541900d50101eu9r.html win7于ubuntu双系统,进入windows后直接格式化硬盘分区将ubuntu删 ...

  4. 在OCX初始化时获取其在网页中的DOM对象

    OCX初始化的时候会调用SetClientSite,会传入IOleClientSite对象. CComQIPtr<IOleControlSite, &IID_IOleControlSit ...

  5. sicily 1007 To and Fro

    题意:字符串的操作处理 // Problem#: 8768 // Submission#: 2606406 // The source code is licensed under Creative ...

  6. 《Learn python the hard way》Exercise 48: Advanced User Input

    这几天有点时间,想学点Python基础,今天看到了<learn python the hard way>的 Ex48,这篇文章主要记录一些工具的安装,以及scan 函数的实现. 首先与Ex ...

  7. html5标签收集

    <meta name="viewport" content="width=device-width,initial-scale=1 user-scalable=0& ...

  8. web工程调用hadoop集群1.2

    本实例代码在lz的资源中有上传,有需要的可以参考(下载后的文件解压后有两个,一个直接导入myeclipse工程,另外的jar放在hadoop的lib下面,只需修改Utils中的ip即可运行该程序): ...

  9. Gunplot 命令大全

    在linux命令提示符下运行gnuplot命令启动,输入quit或q或exit退出. plot命令 gnuplot> plot sin(x) with line linetype 3 linew ...

  10. Android调试系列—使用android studio调试smali代码

    1.工具介绍 使用工具 android killer:用于反编译apk包,得到smali代码 android studio:调试smali代码工具,或者使用idea,android studio就是在 ...