• HDU 5127.Dogs' Candies-STL(vector)神奇的题,set过不了 (2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大))


    周六周末组队训练赛。

    Dogs' Candies

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


    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
     

    题意就是1为插入,0为查询,-1为删除。

    直接暴力,我也是服了,垃圾题目,set过不了。

    代码:

     1 //hdu5127-A-vector,直接数组都可以过
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<bitset>
     7 #include<cassert>
     8 #include<cctype>
     9 #include<cmath>
    10 #include<cstdlib>
    11 #include<ctime>
    12 #include<deque>
    13 #include<iomanip>
    14 #include<list>
    15 #include<map>
    16 #include<queue>
    17 #include<set>
    18 #include<stack>
    19 #include<vector>
    20 using namespace std;
    21 typedef long long ll;
    22 
    23 const double PI=acos(-1.0);
    24 const double eps=1e-6;
    25 const ll mod=1e9+7;
    26 const int inf=0x3f3f3f3f;
    27 const int maxn=1e5+10;
    28 const int maxm=100+10;
    29 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    30 #define lson l,m,rt<<1
    31 #define rson m+1,r,rt<<1|1
    32 
    33 struct node{
    34     ll x,y;
    35 };
    36 
    37 vector<node> vec;
    38 
    39 int main()
    40 {
    41     int n;
    42     while(scanf("%d",&n)&&n)
    43     {
    44         vec.clear();
    45         for(int i=1;i<=n;i++)
    46         {
    47             ll op,a,b;
    48             scanf("%lld%lld%lld",&op,&a,&b);
    49             if(op==1)
    50             {
    51                 vec.push_back({a,b});
    52             }
    53             else if(op==0)
    54             {
    55                 ll ans=-inf;
    56                 for(auto it:vec){
    57                     ans=max(ans,a*it.x+b*it.y);
    58                 }
    59                 printf("%lld
    ",ans);
    60             }
    61             else if(op==-1)
    62             {
    63                 for(vector<node>::iterator it=vec.begin();it!=vec.end();it++){
    64                     node temp=*it;
    65                     if(temp.x==a&&temp.y==b){
    66                         vec.erase(it);
    67                         break;
    68                     }
    69                 }
    70             }
    71         }
    72     }
    73 }

    猪小可爱的set没写过,贴一下,纪念一下,要不白写了。

    超时。

    代码:

     1 //A-set会超时
     2 #include <bits/stdc++.h>
     3 #define pb push_back
     4 #define mp make_pair
     5 #define fi first
     6 #define se second
     7 #define all(a) (a).begin(), (a).end()
     8 #define fillchar(a, x) memset(a, x, sizeof(a))
     9 #define huan printf("
    ")
    10 #define debug(a,b) cout<<a<<" "<<b<<" "<<endl
    11 #define ffread(a) fastIO::read(a)
    12 using namespace std;
    13 typedef long long ll;
    14 typedef pair<int,int> pii;
    15 const int maxn=1e6+10;
    16 const int inf=0x3f3f3f3f;
    17 int main()
    18 {
    19     int n;
    20     while(scanf("%d",&n)&&n)
    21     {
    22         set<pair<ll,ll> >s;
    23         for(int i=0;i<n;i++)
    24         {
    25             ll k,x,y;
    26             scanf("%lld%lld%lld",&k,&x,&y);
    27             if(k==1)
    28             {
    29                 s.insert(mp(x,y));
    30             }
    31             else if(k==-1)
    32             {
    33                 s.erase(mp(x,y));
    34             }
    35             else
    36             {
    37                 ll maxx=-3e18;
    38                 for(auto it:s)
    39                 {
    40                     //cout<<it.fi<<" "<<it.se<<endl;
    41                     maxx=max(maxx,x*it.fi+y*it.se);
    42                 }
    43                 //if(maxx==-inf)
    44                 printf("%lld
    ",maxx);
    45             }
    46         }
    47     }
    48 }
    View Code

    OK。

  • 相关阅读:
    权限管理系统准备
    java启动线程时 extends与implements的一个差异
    spring中使用quartz时注入时出现的错误
    bat执行java程序 good
    bat下执行java程序报错处理
    SQLite.dll在xp中部署时的报错处理
    hdu 4277 USACO ORZ (dfs暴搜+hash)
    Java实现 蓝桥杯 算法训练 动态数组使用
    Java实现 蓝桥杯 算法训练 动态数组使用
    Java实现 蓝桥杯 算法训练 动态数组使用
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9793678.html
Copyright © 2020-2023  润新知