周六周末组队训练赛。

Dogs' Candies

Time Limit: 30000/30000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 3920    Accepted Submission(s): 941

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 <= n <= 50000).

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
 

题意就是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亚洲区广州站-重现赛(感谢华工和北大))的更多相关文章

  1. 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 ...

  2. 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 ...

  3. HDU 5112 A Curious Matt (2014ACM/ICPC亚洲区北京站-重现赛)

    A Curious Matt Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) ...

  4. HDU 5127 Dogs' Candies

    Dogs' Candies Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) T ...

  5. Hdu OJ 5113 Black And White (2014ACM/ICPC亚洲区北京站) (搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5113 题目大意:有k种颜色的方块,每种颜色有ai个, 现在有n*m的矩阵, 问这k种颜色的方块能否使任 ...

  6. Hdu OJ 5115 Dire Wolf (2014ACM/ICPC亚洲区北京站) (动态规划-区间dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115 题目大意:前面有n头狼并列排成一排, 每一头狼都有两个属性--基础攻击力和buff加成, 每一头 ...

  7. 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 ...

  8. hdu 5122(2014ACM/ICPC亚洲区北京站) K题 K.Bro Sorting

    传送门 对于错想成lis的解法,提供一组反例 1 3 4 2 5同时对于这次案例也可以观察出解法:对于每一个数,如果存在比它小的数在它后面,它势必需要移动,因为只能小的数无法向右移动,而且每一次移动都 ...

  9. 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代码 ...

随机推荐

  1. 【Linux】NAT模式下关于主机ping不通虚拟机的问题

    今天打开虚拟机,然后用Xshell远程连接,发现连接不上.按照以下顺序检查了一遍. 1.虚拟机网络连接采用的是NAT模式 2.虚拟机IP采用的是自动获取.   IP:192.168.191.130 子 ...

  2. zoj 1729 Hidden Password

    Hidden Passwordhttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=729 Time Limit: 2 Seconds ...

  3. [Luogu 2604] ZJOI2010 网络扩容

    [Luogu 2604] ZJOI2010 网络扩容 第一问直接最大流. 第二问,添加一遍带费用的边,边权 INF,超级源点连源点一条容量为 \(k\) 的边来限流,跑费用流. 大约是第一次用 nam ...

  4. 地精排序Gnome Sort

    号称最简单的排序算法,只有一层循环,默认情况下前进冒泡,一旦遇到冒泡的情况发生就往回冒,直到把这个数字放好为止 直接看它排序的过程,待排数组[6 2 4 1 5 9] 先设计一个标识i=0然后从头开始 ...

  5. 阿里云maven仓库地址,速度提升100倍

    参照:https://www.cnblogs.com/xxt19970908/p/6685777.html maven仓库用过的人都知道,国内有多么的悲催.还好有比较好用的镜像可以使用,尽快记录下来. ...

  6. jQuery拖拽 & 弹出层

    了解更多请查看 官网 和 API iDrag & iDialog 介绍 特点: iDialog.js依赖于jquery编写的简单易用的对话框,同时还可以通过添加css3,改变对话框的展现动画. ...

  7. windows修改文件的修改或者创建时间

    https://www.online-tech-tips.com/computer-tips/how-to-change-the-last-modified-date-creation-date-an ...

  8. 【LibreOJ】#541. 「LibreOJ NOIP Round #1」七曜圣贤

    [题意]一开始车上有编号为0~a的红茶,过程中出现的红茶编号仅有[0,b),有三种操作: 1.买进编号未在车上出现过的红茶. 2.丢掉车上指定编号的红茶. 3.将最早丢出去的红茶捡回来. 每次操作后求 ...

  9. 牛客网刷题(纯java题型 1~30题)

    牛客网刷题(纯java题型 1~30题) 应该是先extend,然后implement class test extends A implements B { public static void m ...

  10. ES6新增的let与const

    1.const 声明常量,一旦声明必须立马赋值,否则报错 const PI = 3.14 const PI; //报错:Uncaught SyntaxError: Missing initialize ...