HDU - 5127 Dogs‘ Candies 暴力 懒人删除法

Training 2 - A题

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

#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 50000 + 20;

struct Node
{
	ll x;
	ll y;
	bool del;
};
Node c[maxn];

int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		memset(c, 0, sizeof(c));
		if (n == 0)
			break;
		int pos = 0;
		for (ll i = 0; i < n; i++)
		{
			int t;
			ll x, y;
			scanf("%d%lld%lld", &t, &x, &y);
			if (t == -1)
			{
				for (ll j = 0; j < pos; j++)
				{
					if (c[j].x == x && c[j].y == y)
					{
						c[j].del = 0;
					}
				}
			}
			if (t == 0)
			{
				ll ans = -inf;
				for (ll j = 0; j < pos; j++)
					if (c[j].del == 1)
						ans = max(ans, (ll)c[j].x * x + (ll)c[j].y * y);
				printf("%lld\n", ans);
			}
			if (t == 1)
			{
				c[pos].x = x;
				c[pos].y = y;
				c[pos++].del = 1;
			}
		}
	}
	return 0;
}

思路:
暴力O(n)做法。用数组模拟链表,删除时的操作是改变用记录当前节点是否删除的bool型变量的值。
需要注意,存在反复增加和删除节点的操作,需要在删除节点时删除所有当前节点。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值