HDU5127 Dogs' Candies(瞎暴力)

2023-10-06 00:19
文章标签 暴力 candies hdu5127 dogs

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

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;
}


这篇关于HDU5127 Dogs' Candies(瞎暴力)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/152375

相关文章

计蒜客 Half-consecutive Numbers 暴力打表找规律

The numbers 11, 33, 66, 1010, 1515, 2121, 2828, 3636, 4545 and t_i=\frac{1}{2}i(i+1)t​i​​=​2​​1​​i(i+1), are called half-consecutive. For given NN, find the smallest rr which is no smaller than NN

10125-Sumsets【暴力】

利用n^2的时间枚举所有a[i] + a[j] 利用n^2的时间枚举所有a[i] - a[j] 之后利用n^2时间一个一个找a[i] - a[j]的值是否存在于a[i] + a[j]中 找的时候需要二分查找 另外一点就是注意long long的范围以及四个数是集合内不同的四个元素 15222638 10125 Sumsets Accepted C++ 0.449 2015-03-

10730-Antiarithmetic?【暴力枚举】

水题 求一个序列是否存在3个数按顺序构成等差数列 直接枚举等差数列的差值 时间复杂度降到 n * n / 3 开pos数组记录每个值得为之 楷vis数组记录目前i是否出现过 强行AC 15221397 10730 Antiarithmetic? Accepted C++ 0.035 2015-03-26 12:09:56 #include<cstdio>#include

HLJUOJ1125(暴力三点一线)

两点确定一条直线 Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 19   Solved: 11 [ Submit][ Status][ Web Board] Description  给一个15000 * 15000 的区域, 坐标都是整数. 其中有N个点,N <= 770.问总共有多少个3点共线的组合.并按升序(点的ID)输出

HLJUOJ1117(暴力模拟)

八数码 Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 109   Solved: 19 [ Submit][ Status][ Web Board] Description 给定一个8数码的初始状态,然后给出一系列对8数码的操作,求其最终状态. Input 第一行t,代表样例个数。 每组数据前三行各三个数,代表八数

CF Bayan 2015 Contest Warm Up B.(dfs+暴力)

B. Strongly Connected City time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/475/probl

UVA10010(八方向暴力枚举)

Where's Waldorf? Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu 题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18656 Description Where's Waldo

CF #278 (Div. 2) B.(暴力枚举+推导公式+数学构造)

B. Candy Boxes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/488/problem/B There

CF#278 (Div. 2) A.(暴力枚举)

A. Giga Tower time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output 题目链接: http://codeforces.com/contest/488/problem/A Giga To

CF#284 (Div. 2) B.(暴力)

题目链接:http://codeforces.com/contest/499/problem/B 解题思路: 开一个is变量记录每组单词最后应该输出哪个。最后每次把原来的数组暴力扫一遍即可。 完整代码: #include <functional>#include <algorithm>#include <iostream>#include <fstream>#inc