题意:供应商提供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. Qt for Windows - Deployment和它的参数

    http://doc.qt.io/qt-5/windows-deployment.html

  2. Android Studio 设置LogCat 颜色

    1. File -> Settings ->Search LogCat 2. Save a schema first, for instance: MyLogCatStyle 3. cho ...

  3. zoj2112

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2112 经典的动态区间第K大. 用树状数组套线段树. 对原数组建一个树 ...

  4. 用于防SQL注入的几个函数

    不要相信用户的在登陆中输入的内容,需要对用户的输入进行处理 SQL注入: ' or 1=1 # 防止SQL注入的几个函数: addslashes($string):用反斜线引用字符串中的特殊字符' & ...

  5. MVC MVC 路由详解

    在项目中我们引用了System.Web.Routing;   Routing的作用: 确定Controller 确定Action 确定其他参数 根据识别出来的数据, 将请求传递给Controller和 ...

  6. 在ubuntu14.04上部署hadoop2.6.3

    一.在Ubuntu下创建hadoop组和hadoop用户 增加hadoop用户组,同时在该组里增加hadoop用户,后续在涉及到hadoop操作时,我们使用该用户. 1.创建hadoop用户组 2.创 ...

  7. (转)iOS7界面设计规范(2) - UI基础 - iOS应用解析

    今天再来一发,然后结束掉周六的忙碌,去吃零食,还有冰啤酒:其实现在打嗝还有小龙虾味儿呢. 第二篇更多的是从技术的角度对iOS界面组成原理进行了简单的解析,篇幅很短,可稍作了解:更多关于iOS开发入门的 ...

  8. javascript实现的有缩略图功能的幻灯片切换效果

    不久前写了一个简单的图片效果,没想到那么快就要用到项目中,所以功能方面要丰富一下: 主要改进: 1# 用圆点代替之前简单的页数显示,并且点击圆点可以显示对应图片: 2# 点击圆点,显示对应图片的缩略图 ...

  9. Android Studio编译好的apk放在哪里?

    Eclipse中编译好的apk文件时在bin文件中面的,可是在Android Studio有一个比較大的修改了,编译好的apk在android studio里面是直接看不到了,并且apk文件所在文件夹 ...

  10. [转]iOS开发使用半透明模糊效果方法整理

    转自:http://www.molotang.com/articles/1921.html 虽然iOS很早就支持使用模糊效果对图片等进行处理,但尤其在iOS7以后,半透明模糊效果得到大范围广泛使用.包 ...