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 ...
随机推荐
- hdu 4112 Break the Chocolate(ceil floor)
规律题: #include<stdio.h> #include<math.h> #define eps 1e-8 int main() { int _case; int n,m ...
- log log4net用代码记录日志
log4net 用代码记录日志 今天在开发项目的时候,遇到跨域调用log4net中的类,出现了一个bug,提示LogImpl未标记可序列化,此时,我靠,麻烦了,这个类又不是咱们自己的,改源码我想应该 ...
- 分析和解析PHP代码的7大工具
PHP已成为时下最热门的编程语言之一,然而却有许多PHP程序员苦恼找不到合适的工具来帮助自己分析和解析PHP代码.今天小编就为大家介绍几个非常不错的工具,来帮助程序员们提高自己的工作效率,一起来看看吧 ...
- jenkins的搭建和使用
Jenkins 是一个开源项目,提供了一种易于使用的持续集成系统,使开发者从繁杂的集成中解脱出来,专注于更为重要的业务逻辑实现上.同时 Jenkins 能实施监控集成中存在的错误,提供详细的日志文件和 ...
- 截取usb数据包,控制usb设备----Relay设备
在项目开发当中,我们需要一个usb转继电器的设备当开关控制无线发射设备,采购部采购时并未详细了解Relay设备的运行环境就买了一批设备,之后发现设备厂家只提供了windows库,而我们是要在linux ...
- Android控件系列之CheckBox
学习目的: 1.掌握在Android中如何建立CheckBox 2.掌握CheckBox的常用属性 3.掌握CheckBox选中状态变换的事件(监听器) CheckBox简介: CheckBox和Bu ...
- Java中的ArrayList的初始容量和容量分配
List接口的大小可变数组的实现.实现了所有可选列表操作,并允许包括 null 在内的所有元素.ArrayList继承于List接口,除继承过来的方法外,还提供一些方法来操作内部用来存储列表的数组的大 ...
- BZOJ 3170 松鼠聚会(XY坐标)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=3170 题意:给出二维平面上n个点 (xi,yi).求一点t(1<=t<=n) ...
- java操作office和pdf文件页面列表导出cvs,excel、pdf报表.
在平常的开发中我们常常遇到不仅仅只是导出excel报表的情况.有时候也需要导出pdf或者CSV报 表.其实原理都差不多.刚开始本来不打算也这篇博客介绍这个的.感觉这篇博客和前面的博客有点雷同.原理基本 ...
- 关于结构化BOM的思考
参加了今天的"自主生产音箱类产品BOM结构问题"(即非采购而是制造的音箱)会议,我发现大家在会议上呈现的产品结构对生产计划的层级需求已上升到5层的需求了,又找段会胜要了各位前期就此 ...