周六周末组队训练赛。

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
2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大)

题意就是1为插入,0为查询,-1为删除。

直接暴力,我也是服了,垃圾题目,set过不了。

代码:

 1 //hdu5127-A-vector,直接数组都可以过
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<bitset>
 7 #include<cassert>
 8 #include<cctype>
 9 #include<cmath>
10 #include<cstdlib>
11 #include<ctime>
12 #include<deque>
13 #include<iomanip>
14 #include<list>
15 #include<map>
16 #include<queue>
17 #include<set>
18 #include<stack>
19 #include<vector>
20 using namespace std;
21 typedef long long ll;
22
23 const double PI=acos(-1.0);
24 const double eps=1e-6;
25 const ll mod=1e9+7;
26 const int inf=0x3f3f3f3f;
27 const int maxn=1e5+10;
28 const int maxm=100+10;
29 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
30 #define lson l,m,rt<<1
31 #define rson m+1,r,rt<<1|1
32
33 struct node{
34     ll x,y;
35 };
36
37 vector<node> vec;
38
39 int main()
40 {
41     int n;
42     while(scanf("%d",&n)&&n)
43     {
44         vec.clear();
45         for(int i=1;i<=n;i++)
46         {
47             ll op,a,b;
48             scanf("%lld%lld%lld",&op,&a,&b);
49             if(op==1)
50             {
51                 vec.push_back({a,b});
52             }
53             else if(op==0)
54             {
55                 ll ans=-inf;
56                 for(auto it:vec){
57                     ans=max(ans,a*it.x+b*it.y);
58                 }
59                 printf("%lld\n",ans);
60             }
61             else if(op==-1)
62             {
63                 for(vector<node>::iterator it=vec.begin();it!=vec.end();it++){
64                     node temp=*it;
65                     if(temp.x==a&&temp.y==b){
66                         vec.erase(it);
67                         break;
68                     }
69                 }
70             }
71         }
72     }
73 }

猪小可爱的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 }

View Code

OK。

转载于:https://www.cnblogs.com/ZERO-/p/9793678.html

HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))...相关推荐

  1. hdu 5131 Song Jiang#39;s rank list 【2014ACM/ICPC亚洲区广州站-重现赛】

    Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java ...

  2. HDU 5514 Collision(扩展欧几里得+解方程)——2014ACM/ICPC亚洲区北京站

    传送门 Matt is playing a naive computer game with his deeply loved pure girl. The playground is a recta ...

  3. C++ stl vector介绍

    转自: STL vector用法介绍 介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if ...

  4. STL vector的几种清空容器(删除)办法

    1.为什么需要主动释放vector内存 来自 <https://blog.csdn.net/hellokandy/article/details/78500067> vector其中一个特 ...

  5. STL vector 容器介绍

    介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用.通 ...

  6. STL vector的erase操作问题

    STL vector的erase操作问题 一老大说CSDN上有篇博文("关于STL vector的erase操作",地址是:http://blog.csdn.net/tingya/ ...

  7. STL vector容器

    介绍  这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用. ...

  8. stl vector 函数_在C ++ STL中使用vector :: begin()和vector :: end()函数打印矢量的所有元素...

    stl vector 函数 打印向量的所有元素 (Printing all elements of a vector) To print all elements of a vector, we ca ...

  9. stl vector 函数_vector :: at()函数以及C ++ STL中的示例

    stl vector 函数 C ++ vector :: at()函数 (C++ vector::at() function) vector::at() is a library function o ...

最新文章

  1. 神奇的 SQL,Group By 真扎心,原来是这样!
  2. matlab模型参数不匹配怎么办,修改Simulink模型后出现初始状态大小不匹配的错误...
  3. 史上最全Redis面试题及答案。
  4. WinAPI: waveOutGetErrorText - 根据错误号得到错误描述
  5. 基于requests模块的cookie,session和线程池爬取
  6. json文件读取并转换成为字典python
  7. Java String类的相关操作
  8. 2018年,AI会在金融行业哪些方向上发力?
  9. 已知前序(先序)与中序输出后序
  10. python计算工资编程-当财务部的人会编程,会发生什么?Python实现自动化群发工资条...
  11. centos7.5部署mysql cluster NDB总结
  12. 教你6步从头写机器学习算法——以感知机算法为例
  13. 波特率和比特率的关系
  14. android 多个 前台 挂机,安卓手机如何进行多开挂机?
  15. 2022暑期牛客多校训练第5场 A.Don‘t Starve
  16. civil 3d 计算机配置,Civil 3D技巧:如果做到设计文件的高效出图?
  17. 【cocos精品】《梦幻西游》全面制霸苹果榜单 四榜登顶
  18. 订单打标java_java 操作打标机的Dll 文件
  19. Magnetic Levitation for Soft-Tethered Capsule Colonoscopy Actuated With a Single Permanent Magnet
  20. mysql配置数据库邮件_SqlServer2008怎么配置数据库邮件?

热门文章

  1. fritzing导入元件_【工具】【电子设计】超屌的 fritzing 新建元件
  2. 51单片机步进电机全套资料(启停+正反转+加减速+显示速度+中断)【源程序+流程图+接线图+视频+答辩报告】综合设计首选
  3. gin+grom+jwt+mysql
  4. 3、OmniGraffle系列-泳道图
  5. visio如何去掉泳道左边的分隔符
  6. 广告语中常用非法的词语,夸大性质的关键字
  7. 【调剂】哈尔滨工程大学现代海洋信息技术团队2023年招收第一志愿学生和调剂的硕士研究生...
  8. 【微信小程序】预览视频
  9. Ubuntu资源暂时不可用 E: 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)
  10. java flowlayout参数_【Java布局】FlowLayout布局时设定组件大小