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代码 ...
随机推荐
- sql 语句 插入数据 返回值问题
1. 主键ID 自增 ,插入数据后返回这条数据的ID值 insert into tableName() values() select @@identity 2.主键ID 使用GUID类型值 ,插入数 ...
- asp:DropDownList与asp:DataList的联合使用
情况:当在asp:DropDownLis点击选取其中的一个值来响应datalist的值. <form id="form1" runat="server"& ...
- vijos 1655 萌萌的糖果博弈 博弈
背景 用糖果来引诱小朋友学习是最常用的手法,绵羊爸爸就是用糖果来引诱萌萌学习博弈的. 描述 他把糖果分成了两堆,一堆有A粒,另一堆有B粒.他让萌萌和他一起按照下面的规则取糖果:每次可以任意拿走其中一堆 ...
- 「模板」「讲解」Treap名次树
Treap实现名次树 前言 学平衡树的过程可以说是相当艰难.浏览Blog的过程中看到大量指针版平衡树,不擅长指针操作的我已经接近崩溃.于是,我想着一定要写一篇非指针实现的Treap的Blog. 具体如 ...
- Flask中路由原理
在Flask内部使用两张表维护路由: url_map :维护URL规则和endpoint的映射 view_functions :维护endpoint和视图函数的映射. 以用户访问URL/home为例, ...
- python实现备份gitlab版本库并更改文件名
脚本的功能是实现备份gitlab版本库,并修改备份后的文件名,成功后发送邮件至相关负责人,脚本如下: #!/usr/bin/env python # -*- coding:utf-8 -*- impo ...
- UIPikerView的属性---iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/C ...
- 牛客网刷题(纯java题型 1~30题)
牛客网刷题(纯java题型 1~30题) 应该是先extend,然后implement class test extends A implements B { public static void m ...
- 教你 Shiro 整合 SpringBoot,避开各种坑(山东数漫江湖)
依赖包 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-sprin ...
- Spring boot集成RabbitMQ(山东数漫江湖)
RabbitMQ简介 RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统 MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出 ...