HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))
周六周末组队训练赛。
Dogs' Candies
Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 3920 Accepted Submission(s): 941
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.
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.
0
题意就是1为插入,0为查询,-1为删除。
直接暴力,我也是服了,垃圾题目,set过不了。
代码:
//hdu5127-A-vector,直接数组都可以过
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll; const double PI=acos(-1.0);
const double eps=1e-;
const ll mod=1e9+;
const int inf=0x3f3f3f3f;
const int maxn=1e5+;
const int maxm=+;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 struct node{
ll x,y;
}; vector<node> vec; int main()
{
int n;
while(scanf("%d",&n)&&n)
{
vec.clear();
for(int i=;i<=n;i++)
{
ll op,a,b;
scanf("%lld%lld%lld",&op,&a,&b);
if(op==)
{
vec.push_back({a,b});
}
else if(op==)
{
ll ans=-inf;
for(auto it:vec){
ans=max(ans,a*it.x+b*it.y);
}
printf("%lld\n",ans);
}
else if(op==-)
{
for(vector<node>::iterator it=vec.begin();it!=vec.end();it++){
node temp=*it;
if(temp.x==a&&temp.y==b){
vec.erase(it);
break;
}
}
}
}
}
}
猪小可爱的set没写过,贴一下,纪念一下,要不白写了。
超时。
代码:
1 //A-set会超时
2 #include <bits/stdc++.h>
3 #define pb push_back
4 #define mp make_pair
5 #define fi first
6 #define se second
7 #define all(a) (a).begin(), (a).end()
8 #define fillchar(a, x) memset(a, x, sizeof(a))
9 #define huan printf("\n")
10 #define debug(a,b) cout<<a<<" "<<b<<" "<<endl
11 #define ffread(a) fastIO::read(a)
12 using namespace std;
13 typedef long long ll;
14 typedef pair<int,int> pii;
15 const int maxn=1e6+10;
16 const int inf=0x3f3f3f3f;
17 int main()
18 {
19 int n;
20 while(scanf("%d",&n)&&n)
21 {
22 set<pair<ll,ll> >s;
23 for(int i=0;i<n;i++)
24 {
25 ll k,x,y;
26 scanf("%lld%lld%lld",&k,&x,&y);
27 if(k==1)
28 {
29 s.insert(mp(x,y));
30 }
31 else if(k==-1)
32 {
33 s.erase(mp(x,y));
34 }
35 else
36 {
37 ll maxx=-3e18;
38 for(auto it:s)
39 {
40 //cout<<it.fi<<" "<<it.se<<endl;
41 maxx=max(maxx,x*it.fi+y*it.se);
42 }
43 //if(maxx==-inf)
44 printf("%lld\n",maxx);
45 }
46 }
47 }
48 }
OK。
HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))的更多相关文章
- HDU 5135.Little Zu Chongzhi's Triangles-字符串 (2014ACM/ICPC亚洲区广州站-重现赛)
Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 ...
- HDU 5131.Song Jiang's rank list (2014ACM/ICPC亚洲区广州站-重现赛)
Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java ...
- HDU 5112 A Curious Matt (2014ACM/ICPC亚洲区北京站-重现赛)
A Curious Matt Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) ...
- HDU 5127 Dogs' Candies
Dogs' Candies Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) T ...
- Hdu OJ 5113 Black And White (2014ACM/ICPC亚洲区北京站) (搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5113 题目大意:有k种颜色的方块,每种颜色有ai个, 现在有n*m的矩阵, 问这k种颜色的方块能否使任 ...
- Hdu OJ 5115 Dire Wolf (2014ACM/ICPC亚洲区北京站) (动态规划-区间dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目大意:前面有n头狼并列排成一排, 每一头狼都有两个属性--基础攻击力和buff加成, 每一头 ...
- HDU 6237.A Simple Stone Game-欧拉函数找素因子 (2017中国大学生程序设计竞赛-哈尔滨站-重现赛)
A Simple Stone Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- hdu 5122(2014ACM/ICPC亚洲区北京站) K题 K.Bro Sorting
传送门 对于错想成lis的解法,提供一组反例 1 3 4 2 5同时对于这次案例也可以观察出解法:对于每一个数,如果存在比它小的数在它后面,它势必需要移动,因为只能小的数无法向右移动,而且每一次移动都 ...
- HDU 5115 (2014ACM/ICPC亚洲区北京站) D题(Dire Wolf)
题目传送门 设dp[i][j]为杀掉区间i到j之间的狼需要付出的最小代价,那么dp[i][j]=min{dp[i][k-1]+dp[k+1][j]+a[k]+b[i-1]+b[j+1]} Java代码 ...
随机推荐
- annot refer to a non-final variable * inside an inner class defined in a different method"错误解析
在使用Java局部内部类或者匿名内部类时,若该类调用了所在方法的局部变量,则该局部变量必须使用final关键字来修饰,否则将会出现编译错误“Cannot refer to a non-final va ...
- [洛谷P3763] [TJOI2017]DNA
洛谷题目链接:[TJOI2017]DNA 题目描述 加里敦大学的生物研究所,发现了决定人喜不喜欢吃藕的基因序列S,有这个序列的碱基序列就会表现出喜欢吃藕的性状,但是研究人员发现对碱基序列S,任意修改其 ...
- iOS排序
NSArray *originalArray = @[@,@,@,@,@]; //block比较方法,数组中可以是NSInteger,NSString(需要转换) NSComparator finde ...
- JAVA中3种将byte转换为String的方法
HttpClient 类库中GetMethod类的getResponseBody方法返回的是byte[]类型,要操作起来不方便,我想把它转化成String类型. 查了网上的资料,有说法认为用这种方法比 ...
- android程序员成长路径的思考
我之前就想过要写这个话题,不过之前没有什么认识,我只是在阅读别人的见解,看法.昨天晚上,我阅读了这篇文章<产品经理罗永浩:用户体验探索,没有尽头>,这篇文章描述了罗永浩对锤子手机设计细节的 ...
- End to End Sequence Labeling via Bidirectional LSTM-CNNs-CRF论文小结
本篇论文是卡内基梅隆大学语言技术研究所2016年 arXiv:1603.01354v5 [cs.LG] 29 May 2016 今天先理解一下这个是什么意思: 找到的相关理解:arXi ...
- shell 文件内容替换 sed用法
sed 's/要被替换的字符串/新的字符串/g' sed 's/test/mytest/g' example-----在整行范围内把test替换为mytest. 如果没有g标记,则只有每行第一个匹配的 ...
- [session篇]看源码学习session(一)
假如你是使用过或学习过PHP,你一定觉得很简单.session只不过是$_SESSION就可以搞得,这还不简单只是对一个key-value就能工作了.我觉得可以大多数的phper都是这样的,这是语言本 ...
- 【模板】BZOJ 3781: 小B的询问 莫队算法
http://www.lydsy.com/JudgeOnline/problem.php?id=3781 N个数的序列,每次询问区间中每种数字出现次数的平方和,可以离线. 丢模板: #include ...
- [How to] 动态布局可变高度的cell的应用
1.简介 代码:https://github.com/xufeng79x/DynamicChangeableCell 微博界面,微信和QQ聊天界面,这些界面的布局大都不确定,且每一条消息的高度也不一样 ...