HDU 5127 Dogs' Candies
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的更多相关文章
- HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))
周六周末组队训练赛. Dogs' Candies Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K ( ...
- hdu 2822 Dogs
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2822 Dogs Description Prairie dog comes again! Someda ...
- hdu 1514 Free Candies 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1514 题目意思:有4堆糖果,每堆糖果有n个,从上到下排好,取糖果只能从上往下取,取完的糖果放在篮子里, ...
- hdu - 2822 Dogs (优先队列+bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2822 给定起点和终点,问从起点到终点需要挖几次只有从# 到 .或者从. 到 . 才需要挖一次. #includ ...
- hdu5127 Dogs' Candies CDQ分治 动态凸包
传送门 题意 有三种操作 加入一个二元组\((x,y)\) 删除一个二元组\((x,y)\) 给出一个二元组\((a,b)\),问\(ax+by\)的最大值 题解 \(z=ax+by \Rightar ...
- hdu 2822 Dogs(优先队列)
题目链接:hdu2822 会优先队列话这题很容易AC.... #include<stdio.h> #include<string.h> #include<queue> ...
- DP的优化总结
一.预备知识 \(tD/eD\) 问题:状态 t 维,决策 e 维.时间复杂度\(O(n^{e+t})\). 四边形不等式: 称代价函数 w 满足凸四边形不等式,当:\(w(a,c)+w(b,d)\l ...
- HDU 6126.Give out candies 最小割
Give out candies Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- hdu 6126 Give out candies
hdu 6126 Give out candies(最小割) 题意: 有\(n\)个小朋友,标号为\(1\)到\(n\),你要给每个小朋友至少\(1\)个且至多\(m\)个的糖果.小朋友们共提出\(k ...
随机推荐
- Jlink更新新固件USB连接不上的问题
采购新买了一个jlink,在调试过程中发现不能使用.拿到手后对jink上电以后,发现灯不亮,到网上查了一下估计是固件损坏的原因,经过一番摸索从新更新了固件,然后可以正常使用了,下面说一下步骤: 新版的 ...
- My SQL InnoDB 1217 - Cannot delete or update a parent row:aforeign key constraint fals
InnoDB 允许有外键 MyISAM 不允许有外键 InnoDB修改成MyISAM 证明有外键 一张表如果有其他表的外键关联的是它 它也不能是MyISAM 来自为知笔记(Wiz)
- 针对安卓java入门:方法的使用
[修饰符]返回值类型 方法名 (形式参数表){ 程序代码; return 返回值; } 例子: public class Test { //方法一 public static void printIn ...
- 【PPT分享】五类常见的用户分析场景
以下是参加一次沙龙的PPT,分享给大家.关于如何做用户分析的5类场景. 引言 借助“多渠道营销分析”,探究用户从哪里来?如何来? 平台和渠道矩阵 平台和渠道矩阵 跨平台和渠道访问特征分析 多渠道来源分 ...
- 【Tech】Cassandra安装和启动
1.安装 jre,配置系统环境变量: 2.安装python,配置环境变量: 3.下载cassandra,http://cassandra.apache.org/download/: 4.解压,这里我没 ...
- C#服务启动以及服务指令
Windows系统中使用 cmd 命令安装和卸载服务方法如下: 第一种方法: 1. 开始->运行->cmd 2. cd到C:\WINDOWS\Microsoft.NET\Framework ...
- Java用于取得当前日期相对应的月初,月末,季初,季末,年初,年末时间
package com.zrar.date; import java.util.Calendar; /** * * 描述:此类用于取得当前日期相对应的月初,月末,季初,季末,年初,年末,返回值均为St ...
- framework-Binder
init进程fork servicemanager进程用来提供(server)注册service和(client)检索service功能.servicemanager维护了一个service列表,cl ...
- 【分享】IT产业中的三大定理(一) —— 摩尔定理(Moore's Law)
科技行业流传着很多关于比尔·盖茨的故事,其中一个是他和通用汽车公司老板之间的对话.盖茨说,如果汽车工业能够像计算机领域一样发展,那么今天,买一辆汽车只需要 25 美元,一升汽油能跑四百公里.通用汽车老 ...
- MongoDB安装Windows服务
由于官方下载较慢.这里提供一个个人百度共享网盘地址: http://pan.baidu.com/s/1mhHW0nI mongodb-win32-x86_64-3.2.3 使用以下命令将MongoDB ...