HDU 5127 Dogs' Candies(瞎暴力)

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


题意:

有好多只狗和一个狗王,有一个盒子,狗子们往盒子里放糖,每块糖有两个属性 x 和 y 。(数据保证(x,y)不重复,相当于坐标点不重复)

现在有三种操作:

1 : 一只狗往盒子里放一块糖,属性为 x  ,y

-1: 狗王从盒子里拿出一块属性为 x , y  的糖吃掉

0: 一只傻狗想知道如果他给出俩数p ,q 怎样和盒子里的糖果的属性结合算一个数使这个数最大,公式是p×x + q×y.


思路:

题上时间要求30s,瞎暴力随便跑,不跑不必要的程序就不会超时。

我的方法是定义结构体,存糖果的俩属性及这个糖果是否存在(因为狗王会吃掉糖果)

然后有傻狗提问的时候就暴力跑一遍,找到存在的糖果满足上式的最大值

跑了 8s 多

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <set>
using namespace std;
typedef long long LL;
const int maxn=50005;
struct aa{
    LL x,y;
    bool cz;

}a[maxn];

int main()
{
    int op,n;
    LL x,y;
    while(scanf("%d",&n)&&n)
    {
        for(int i=0;i<maxn;i++)
            a[i].cz=false;
        int num=0;
        while(n--)
        {scanf("%d%lld%lld",&op,&x,&y);
        if(op==1)
        {
            a[num].x=x;
            a[num].y=y;
            a[num++].cz=true;
        }
        else if(op==-1)
        {
            for(int i=0;i<num;i++)
            {
                if(a[i].cz)
                    if(a[i].x==x&&a[i].y==y)
                    {a[i].cz=false;break;}
            }
        }
        else
        {
            LL max=-999;
            for(int i=0;i<num;i++)
            {
                if(a[i].cz)
                {LL temp=a[i].x*x+a[i].y*y;
                if(temp>max)
                    max=temp;}

            }
            printf("%lld\n",max);
        }}

    }
    return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值