题意:供应商提供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编程之实现属性窗口编辑器

    类似于这种: 就是右下角这个框,有属性名字和对应的value编辑. 这个Widget是作为一个QDockWidget被添加到QMainWindow中的.QMainWindow必须要有centralWi ...

  2. Oracle优化笔记

    2016-11-22   子查询:标量子查询 内联视图(in-line view) 半连接/反连接   标量子查询 select 后跟子查询 类似自定义函数 可用开窗函数之类的改写   内联视图(in ...

  3. 算法导论(第三版)Exercies2.2(插入排序)

    2.2-1: Θ (n3) 2.2-2:插入排序 void selectionSort(int a[], int n) { int i, j, k, key; ; i<n-; i++) { k ...

  4. 【POJ1338】Ugly Numbers(暴力打表)

    打表大军是一股邪恶势力→_→ #include <iostream> #include <cstring> #include <cstdlib> #include ...

  5. win10 下安装、配置、启动mysql

    1.下载http://dev.mysql.com/downloads/mysql/ 2.Community > MySQL Community Server 3.Other Downloads: ...

  6. Java开源报表Jasper入门(2) -- 使用JasperSoft Studio创建一个简单报表

    在接下来的教程中,我们将实现一个简单的JasperReports示例,展现其基本的开发.使用流程.文章很长,不过是以图片居多,文字并不多. 实例中使用最新的Jasper Studio5.2进行报表设计 ...

  7. 使用gfortran将数据写成Grads格式的代码示例

    使用gfortran将数据写成Grads格式的代码示例: !-----'Fortran4Grads.f90' program Fortran4Grads implicit none integer,p ...

  8. Eclipse创建java webproject配置Tomacat和JDK

    在学习AJAX过程中.还用Intellij就有点老旧了,这是后装个Eclipse时,发现这个配置也非常头疼.如今就叫你怎样创建一个webproject,同一时候叫你配置Eclipse. 一.创建一个w ...

  9. eclipse项目转android studio详解

    第一步:项目导入 向AS中导入项目的方法有两种(其实是一种). 方法一:是在eclipse中先导出为gradle(如图1),然后打开AS,找到项目中的gradle文件,直接导入. 方法二:直接在AS中 ...

  10. 自定义HttpHandler

    1.创建自定义类型 2.继承IHttpHandler接口,并实现 3.配置Web.Config文件,注册类型 4.访问 public class QuickMsgSatisticsHandler : ...