• HDU 5127 Dogs' Candies


    Dogs' Candies
    Time Limit: 30000/30000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
    Total Submission(s): 1701 Accepted Submission(s): 404


    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亚洲区广州站-重现赛(感谢华工和北大)
    解析:时间给了30000ms,模拟即可。不过要注意,要选择合适的容器。一般来讲,应遵循以下规则: * 如果需要高效的随即存取,而不在乎插入和删除的效率,使用vector * 如果需要大量的插入和删除,而不关心随即存取,使用list * 如果需要随即存取,并且关心两端数据的插入和删除,使用deque
    ``` #include #include #include #define ll long long using namespace std;

    list<pair<ll, ll> > l;
    list<pair<ll, ll> >::iterator it;

    int main()
    {
    int n;
    while(scanf("%d",&n) && n){
    ll t, x, y;
    while(n--){
    scanf("%I64d%I64d%I64d", &t, &x, &y);
    pair<ll, ll> p(x, y);
    if(t == 1)
    l.push_back(p);
    else if(t == -1){
    for(it = l.begin(); it != l.end(); ++it){
    if(*it == p){
    l.erase(it);
    break;
    }
    }
    }
    else{
    ll res = -1e18;
    for(it = l.begin(); it != l.end(); ++it){
    res = max(res, it->first * x + it->second * y);
    }
    printf("%I64d ", res);
    }
    }
    l.clear();
    }
    return 0;
    }

  • 相关阅读:
    关于三次握手与四次挥手你要知道这些
    seafile看不见repo报500错误的解决方法
    VMWare Workstation 配置docker多macvlan网络方法
    利用Python3的dpkt库进行ARP扫描
    关于LAMP配置Let’s Encrypt SSL证书
    OpenSSL生成CA证书及终端用户证书
    CentOS7.2安装Vim8和YouCompleteMe
    CentOS 7.2安装Jenkins自动构建Git项目
    CentOS 7.2 安装Gerrit 2.14.6
    CentOS7.2编译GCC7.3
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/5998271.html
Copyright © 2020-2023  润新知