Dogs' Candies

Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)

Total Submission(s): 1701 Accepted Submission(s): 404

Problem Description
Far far away, there live a lot of dogs in the forest. Unlike other dogs, those dogs love candies much more than bones.

Every candy has two attributes: the sweetness degree p and the sourness degree q. Different dogs like different candies. A dog also has two attributes: the fondness degree for sweetness x and the fondness degree for sourness y. So the deliciousness degree of a candy for a dog is defined as p×x + q×y.

The dog king has a huge candy box. At first, the box is empty. The king can add candies to the box or take some candies from the box and eat them. There are always some dogs who want to know which candies in the box are the most delicious for them. Please help the king to answer their questions.

Input
The input consists of at most 10 test cases. For each test case, the first line contains an integer n indicating that there are n candy box operations(1 The following n lines describe the n operations.

Each operation contains three integers t, x and y( 0 <= |x|, |y| <= 109). The first integer t may be -1, 0, or 1.

If t equals -1, it means that a candy in the box with sweetness degree x and sourness degree y is eaten by the dog king.

If t equals 1, it means that a candy with sweetness degree x and sourness degree y is added to the candy box.

If t equals 0, it means that a dog with sweetness fondness degree x and sourness fondness degree y wants to know the maximal deliciousness degree of the candies in the box for him.

It is guaranteed that every candy is unique in the box.

The input ends by n = 0.

Output
For each operation in which t equals to 0, you should print the maximal deliciousness degree of the best candy for the dog.


Sample Input

6

1 2 1

1 1 2

1 1 1

0 2 1

-1 2 1

0 2 1

0

Sample Output

5

4

Source
2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大)


解析:时间给了30000ms,模拟即可。不过要注意,要选择合适的容器。一般来讲,应遵循以下规则:
* 如果需要高效的随即存取,而不在乎插入和删除的效率,使用vector
* 如果需要大量的插入和删除,而不关心随即存取,使用list
* 如果需要随即存取,并且关心两端数据的插入和删除,使用deque


```
#include
#include
#include
#define ll long long
using namespace std;

list<pair<ll, ll> > l;

list<pair<ll, ll> >::iterator it;

int main()

{

int n;

while(scanf("%d",&n) && n){

ll t, x, y;

while(n--){

scanf("%I64d%I64d%I64d", &t, &x, &y);

pair<ll, ll> p(x, y);

if(t == 1)

l.push_back(p);

else if(t == -1){

for(it = l.begin(); it != l.end(); ++it){

if(*it == p){

l.erase(it);

break;

}

}

}

else{

ll res = -1e18;

for(it = l.begin(); it != l.end(); ++it){

res = max(res, it->first * x + it->second * y);

}

printf("%I64d\n", res);

}

}

l.clear();

}

return 0;

}

HDU 5127 Dogs' Candies的更多相关文章

  1. HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))

    周六周末组队训练赛. Dogs' Candies Time Limit: 30000/30000 MS (Java/Others)    Memory Limit: 512000/512000 K ( ...

  2. hdu 2822 Dogs

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2822 Dogs Description Prairie dog comes again! Someda ...

  3. hdu 1514 Free Candies 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1514 题目意思:有4堆糖果,每堆糖果有n个,从上到下排好,取糖果只能从上往下取,取完的糖果放在篮子里, ...

  4. hdu - 2822 Dogs (优先队列+bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=2822 给定起点和终点,问从起点到终点需要挖几次只有从# 到 .或者从. 到  . 才需要挖一次. #includ ...

  5. hdu5127 Dogs' Candies CDQ分治 动态凸包

    传送门 题意 有三种操作 加入一个二元组\((x,y)\) 删除一个二元组\((x,y)\) 给出一个二元组\((a,b)\),问\(ax+by\)的最大值 题解 \(z=ax+by \Rightar ...

  6. hdu 2822 Dogs(优先队列)

    题目链接:hdu2822 会优先队列话这题很容易AC.... #include<stdio.h> #include<string.h> #include<queue> ...

  7. DP的优化总结

    一.预备知识 \(tD/eD\) 问题:状态 t 维,决策 e 维.时间复杂度\(O(n^{e+t})\). 四边形不等式: 称代价函数 w 满足凸四边形不等式,当:\(w(a,c)+w(b,d)\l ...

  8. HDU 6126.Give out candies 最小割

    Give out candies Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

  9. hdu 6126 Give out candies

    hdu 6126 Give out candies(最小割) 题意: 有\(n\)个小朋友,标号为\(1\)到\(n\),你要给每个小朋友至少\(1\)个且至多\(m\)个的糖果.小朋友们共提出\(k ...

随机推荐

  1. C逻辑型变量——时控灯例子

    在C99标准颁布之前,我们通常都是用1或者0来表示逻辑的真与假,因此,当我们需要在程序中传递这种逻辑数据时,我们都是用整型数据类型int来表示这种逻辑型数据.然而,使用整型数据类型int来表示逻辑型变 ...

  2. tomcat console

    1.大家都知道,在Tomcat5及其以后的版本中,当启动tomcat之后,是看不到控制台中的manager应用的.Manager的应用还是很有好处的,可以直接在控制台上(类似于weblogic上的co ...

  3. 基于RPC原理的dubbo

    在校期间大家都写过不少程序,比如写个hello world服务类,然后本地调用下,如下所示.这些程序的特点是服务消费方和服务提供方是本地调用关系. 而一旦踏入公司尤其是大型互联网公司就会发现,公司的系 ...

  4. 【web性能】 JS、CSS的合并、压缩、缓存管理

    本篇文章主要讨论下目前JS,CSS 合并.压缩.缓存管理存在的一些问题,然后分享下自己项目中用到的1个处理方案,并提供1个实例下载.   存在的问题: 合并.压缩文件主要有2方面的问题: 1. 每次发 ...

  5. SSIS -->> Data Type

    SSIS和SQL SERVER, .NET数据类型的映射表

  6. SpringBoot配置属性之Server

    SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...

  7. SQLite学习手册(内置函数)

    一.聚合函数: SQLite中支持的聚合函数在很多其他的关系型数据库中也同样支持,因此我们这里将只是给出每个聚集函数的简要说明,而不在给出更多的示例了.这里还需要进一步说明的是,对于所有聚合函数而言, ...

  8. Oracle —— 表结构相关的SQL

    1.表基本信息(Table) select * from user_tables t, user_tab_comments c where c.table_name = t.table_name an ...

  9. PHP包含文件函数include、include_once、require、require_once区别总结

    一.使用语法和简介 1.include() 语法:include(/path/to/filename)include()语句将在其被调用的位置处包含一个文件.包含一个文件与在该语句所在位置复制制定文件 ...

  10. [POJ1050]To the Max(最大子矩阵,DP)

    题目链接:http://poj.org/problem?id=1050 发现这个题没有写过题解,现在补上吧,思路挺经典的. 思路就是枚举所有的连续的连续的行,比如1 2 3 4 12 23 34 45 ...