本文主要是介绍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
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.
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.
6 1 2 1 1 1 2 1 1 1 0 2 1 -1 2 1 0 2 1 0
5 4
先吐槽几句,这道题很坑,好像是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(瞎暴力)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!