sgu Ice-cream Tycoon
题意:供应商提供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的更多相关文章
- HackerRank Ice Cream Parlor
传送门 Ice Cream Parlor Authored by dheeraj on Mar 21 2013 Problem Statement Sunny and Johnny together ...
- 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 ...
- 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 ...
- Ice Cream Tower
2017-08-18 21:53:38 writer:pprp 题意如下: Problem D. Ice Cream Tower Input file: Standard Input Output f ...
- 2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 二分+贪心
/** 题目:2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 链接:http://codeforces.com/gym/101194 题意:给n个木块,堆 ...
- E. Sonya and Ice Cream(开拓思维)
E. Sonya and Ice Cream time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 【HackerRank】Ice Cream Parlor
Sunny and Johnny together have M dollars which they intend to use at the ice cream parlour. Among N ...
- 【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 ...
- 【dfs+理解题意+构造】【待重做】codeforces E. Ice cream coloring
http://codeforces.com/contest/805/problem/E [题意] 染色数是很好确定,最少染色数是max(si)(最小为1,即使所有的si都为0,这样是单节点树形成的森林 ...
- codeforces 686A A. Free Ice Cream(水题)
题目链接: A. Free Ice Cream //#include <bits/stdc++.h> #include <vector> #include <iostre ...
随机推荐
- PowerShell 中使用json对象的性能比较
PowerShell v3 – Creating Objects With [pscustomobject] – it’s fast! September 19, 2011powershell, v3 ...
- openwrt l7过滤qos配置
openwrt l7过滤qos配置 电梯直达 1# 本帖最后由 木鸟 于 2010-7-27 10:22 编辑 openwrt的qos基于hsfc.提供了分类标记,流量控制等功能,可能还有整形 ...
- java基础进阶:SQL的运用
SQL的基础的运用 /* --1.学生表 Student(S,Sname,Sage,Ssex) --S 学生编号,Sname 学生姓名,Sage 出生年月,Ssex 学生性别 --2.课程表 Cour ...
- 轻量级开源嵌入式关系数据库sqlite基本使用及接口初识
preface,先闲来扯下蛋: 嵌入式数据库,NoSQL的是BerkeleyDB和InnoDB,leveDb.TC(个人较不熟悉),关系型嵌入式是SQLite; 服务器性质的NoSQL服务器,如Red ...
- java对象在hibernate持久层的状态
站在持久化层的角度,一个java对象在它的生命周期中,可处于以下4个状态之一: 临时状态(transient):刚刚用new语句创建,还没有被持久化,并且不处于Session的缓存中. 持久化状态(p ...
- c++命名空间瀑布
一般情况,函数放在命名空间外,命名空间内部放置声明 #include<iostream> using namespace std; //一般情况,函数放在命名空间外,命名空间内部放置声明 ...
- 又一编辑神器-百度编辑器-Ueditor
(Lionden<hsdlionden@gmail.com> 转载说明) 前段时间发表过一篇关于“KindEditor在JSP中使用”的博文.这几天在沈阳东软进行JavaWeb方面的实习工 ...
- 关于Spring中的PagedListHolder分页类的分析
PagedListHolder 这个类可以 对分页操作进行封装 文件在:import org.springframework.beans.support.PagedListHolder;下 默认是把查 ...
- 一个不错的PPT,扁平化设计,开放资源,要的进来
开了那么多的博客,没做啥资源贡献,今天共享一个不错的PPT模板.例如以下图所看到的,须要的话留下邮箱 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFp ...
- 用递归翻转一个栈 Reverse a stack using recursion
明白递归语句之前的语句都是顺序运行,而递归语句之后的语句都是逆序运行 package recursion; import java.util.Stack; public class Reverse_a ...