HDU5127 Dogs' Candies(瞎暴力)

题目:

Dogs' Candies

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


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
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   6022  6021  6020  6019  6018 
 

Statistic |  Submit |  Discuss |  Note
思路:

先吐槽几句,这道题很坑,好像是2014年区域赛的题,昨天比赛的时候,看见这道题,大榜上北大清华的都没做。。以为这题很难,但是一看时间给了30秒,就想这肯定是个暴力,结果最后写了几发暴力,总是莫名奇妙的在第27秒的时候WA,不知道问题出在哪,一想还以为是什么高级数据结构,最后也就放弃了,下来一问,别人都是暴力过的。。看了看我们的代码,少了一个标记,WA了好多次。。


首先这道题题意是,狗王有一个糖果箱,里面放了很多糖,有填的,有酸的,每颗糖的甜度为p,酸度为q。

接下来有三种操作:

当t==-1时:狗王从中拿出甜度为x,酸度为y的糖

当t==1时,狗王放进去甜度为x,酸度为y的糖

当t==0时,是一种查询操作,一个小狗有它的糖度和酸度的口味为x,y,你要在箱子里找出最符合他口味的糖,并算出幸福值,p*x+q*y的最大值


题意懂了,题就好像做了,直接暴力。。

代码:

#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <set>
#include <iostream>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f3f3f3f3f
#define mod 10000007
#define debug() puts("what the fuck!!!")
#define N 500010
#define M 1000000
#define ll long long
using namespace std;
ll n;
struct node
{
    ll p,q;
    ll num;
} zz[N];

int main()
{
    ll t,a,b;
    while(scanf("%lld",&n)&&n)
    {
        ll len=0;
        for(ll i=0; i<n; i++)
        {
            scanf("%lld%lld%lld",&t,&a,&b);
            if(t==1)
            {
                zz[len].p=a;
                zz[len].q=b;
                zz[len++].num=1;
            }
            else if(t==0)
            {
                ll maxx=-inf;
                for(ll j=0; j<len; j++)
                {
                    if(zz[j].num)
                    {
                         maxx=max(maxx,a*zz[j].p+b*zz[j].q);
                    }

                }
                printf("%lld\n",maxx);
            }
            else if(t==-1)
            {
                for(ll j=0; j<len; j++)
                    if(zz[j].p==a&&zz[j].q==b&&zz[j].num)
                    {
                        zz[j].num=0;
                        break;
                    }
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值