2018-07-10 第一天

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.
InputThe 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.OutputFor 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

#include<iostream>
#include<map>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
#define ll long long
const int N = 50005;
const int INF = 0x3f3f3f3f;
struct ac {
    int x, y, flag;
};
int main(int argc, char const *argv[]) {
    int n;
    while(cin >> n && n) {
        ac a[N];
        int len = 0;
        for (int i = 0; i < n; i ++) {
            int t, a1, b1;
            cin >> t >> a1  >> b1;
            if (t == 1) {
                a[len].x = a1;
                a[len].y = b1;
                a[len ++].flag = 1;
            }else if (t == -1) {
                for (int j = 0; j < len; j ++) {
                    if (a[j].x == a1 && a[j].y == b1) {
                        a[j].flag = 0;
                    }
                }
            }else if (t == 0) {
                ll sum = -INF;
                for (int j = 0; j < len; j ++) {
                    if (a[j].flag == 0) {
                        continue;
                    }
                    ll sum1 = a[j].x * a1 + a[j].y * b1;
                    if (sum < sum1)
                        sum = sum1;
                }
                cout << sum << endl;
            }

        }
    }
    return 0;
}

附加从大佬拿淘来的代码


#include<iostream>
#include<vector>
using namespace std;
#define ll long long
struct ac{
    ll x, y;
    ac(ll &x1, ll &y1) {
        x = x1;
        y = y1;
    }
};
int main(int argc, char const *argv[]) {
    ll n;
    std::vector<ac> vv;
    std::vector<ac> ::iterator it;
    while(cin>> n && n) {
        for (ll i = 0; i < n; i ++) {
            ll t, x, y;
            cin >> t >> x >> y;
            if (t == 1) {
                vv.push_back(ac(x, y));
            }else if (t == -1) {
                for (it = vv.begin(); it != vv.end(); it ++) {
                    if ((*it).x == x && (*it).y == y) {
                        vv.erase(it);
                        break;
                    }
                }
            }else if (t == 0) {
                ll sum = -1e18;
                for (ll j = 0; j < int (vv.size()); j ++) {
                    ll sum1 = vv[j].x * x + vv[j].y * y;
                    if (sum < sum1)
                        sum = sum1;
                }
                cout << sum << endl;
            }
        }
        vv.clear();
    }
    return 0;
}


唉。后面题感觉都一般,感觉今天很不好。。。。。

/*RW牛逼/

猜你喜欢

转载自blog.csdn.net/henu_jizhideqingwa/article/details/80993294
今日推荐