2018 计蒜之道 初赛 第三场

A. 贝壳找房性价比

题解:按s排序后,斜率最大的点必定在相邻的两点之间。

#pragma warning(disable:4996)
#include<queue>
#include<map>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long 
#define mem(arr,in) memset(arr,in,sizeof(arr))
using namespace std;
typedef pair<int, int> P;

const int maxn = 1e5 + 5;
const int INF = 1e9 + 7;

int T, n;
int va[maxn];

double get(P a, P b) {
    double k1 = (a.first == b.first) ? 1e15 : 1.0*abs(a.second - b.second) / abs(a.first - b.first);
    return k1;
}

int main()
{
    cin >> T;
    while (T--) {
        cin >> n;
        P p[maxn];
        for (int i = 1; i <= n; i++) {
            int u, v;
            scanf("%d%d", &u, &v);
            p[i] = P(u, v);

        }
        sort(p + 1, p + n + 1);

        double ans = 0;
        for (int i = 1; i < n; i++) ans = max(ans, get(p[i], p[i + 1]));
            
        if (ans == 1e15) printf("-1\n");
        else printf("%lf\n", ans);
    }
    return 0;
}

B. 贝壳找房户外拓展(简单)

题解:小数据,模拟就好了。当数据比较大的时候据说是用线段树维护一个矩阵,不会这操作。

#pragma warning(disable:4996)
#include<queue>
#include<map>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long 
#define mem(arr,in) memset(arr,in,sizeof(arr))
using namespace std;
typedef pair<int, int> P;


const int maxn = 1004;
const int mod = 323232323;

int n, m, Q;
int state[maxn][maxn], we[maxn];

int main()
{
    while (scanf("%d %d %d", &n, &m, &Q) != EOF) {

        int cnt = 0;
        char op[2];
        P ca[maxn], de[maxn];

        while (Q--) {
            scanf("%s", op);
            if (op[0] == 'I') {
                ++cnt;
                int l, r, y, pp, qq;
                cin >> l >> r >> y >> pp >> qq;

                l = min(l, r);
                r = max(l, r);

                we[cnt] = y;
                de[cnt] = P(l, r);

                ca[y] = P(pp, qq);
                for (int i = l; i <= r; i++) state[i][y] = cnt;
            }
            else if (op[0] == 'Q') {
                int x, l, r;
                cin >> x >> l >> r;
                l = min(l, r);
                r = max(l, r);
                
                ll sum = 0;
                for (int j = l; j <= r; j++) {
                    if (state[x][j]) {
                        int yy = we[state[x][j]];
                        sum = ((ll)ca[yy].first*sum + (ll)ca[yy].second) % mod;
                    }
                }
                cout << sum << endl;
            }
            else {
                int ma;
                cin >> ma;
                int l = de[ma].first, r = de[ma].second;
                for (int i = l; i <= r; i++) {
                    state[i][we[ma]] = 0;
                }
                we[ma] = 0;
            }
        }
    }
    return 0;
}

C,D待补。。。

posted @ 2018-05-19 19:44  天之道,利而不害  阅读(231)  评论(0编辑  收藏  举报