• Codeforces Round #492 (Div. 2) [Thanks, uDebug!]


    这次的题好奇怪哦。。。

    C - Tesla

    思路:先把跟停车位相邻的车停进去,然后开始转圈。。。

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define pii pair<int, int>
    
    using namespace std;
    
    const int N = 20007;
    const int M = 1e6 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 +7;
    
    int a[4][N], n, k;
    vector<int> ans[3];
    
    pii getPos(int id) {
        if (id < n) return mk(1, id);
        else return mk(2, 2 * n - 1 - id);
    }
    
    void add(int x, int y, int z) {
        ans[0].push_back(x);
        ans[1].push_back(y);
        ans[2].push_back(z);
    }
    
    int main() {
        scanf("%d%d", &n, &k);
    
        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < n; j++) {
                scanf("%d", &a[i][j]);
            }
        }
    
        for(int j = 0; j < n; j++) {
            if(a[0][j] == 0) continue;
            if(a[0][j] == a[1][j]) {
                add(a[0][j], 0, j);
                k--;
                a[1][j] = 0;
            }
        }
    
        for(int j = 0; j < n; j++) {
            if(a[3][j] == 0) continue;
            if(a[3][j] == a[2][j]) {
                add(a[3][j], 3, j);
                k--;
                a[2][j] = 0;
            }
        }
    
        if(k == 2 * n) {
            puts("-1");
            return 0;
        }
    
        while(k > 0) {
            for(int i = 0; i < 2 * n; i++) {
                pii u = getPos(i);
                if(a[u.first][u.second] == 0) continue;
                if(a[u.first ^ 1][u.second] == a[u.first][u.second]) {
                    add(a[u.first][u.second], u.first ^ 1, u.second);
                    k--;
                    a[u.first][u.second] = 0;
                    continue;
                }
    
                pii v = getPos((i + 2 * n - 1) % (2 * n));
                if(a[v.first][v.second] != 0) continue;
                add(a[u.first][u.second], v.first, v.second);
                swap(a[u.first][u.second], a[v.first][v.second]);
            }
        }
    
        printf("%d
    ", ans[0].size());
        for(int i = 0; i < ans[0].size(); i++) {
            printf("%d %d %d
    ", ans[0][i], ans[1][i] + 1, ans[2][i] + 1);
        }
    
        return 0;
    }

    E:

    题目大意:给你n个长度小于1e6的向量,让你把每个向量变成正向或者负向,使得所有向量加起来的长度不超过1.5 * 1e6

    思路:正解是每三个向量中都能找到两个向量合起来 <= 1e6,然后不断合并,最后只会剩下一个或者两个向量,

    如果一个向量肯定 <= 1e6, 如果是两个向量一定 <= 1.5 * 1e6。。。

    但是可以用随机洗牌的方法去贪心,因为能卡掉的数据特别不好造。。。

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define pii pair<int, int>
    
    using namespace std;
    
    const int N = 1e5 + 7;
    const int M = 1e6 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 +7;
    
    int n, ans[N], id[N];
    LL base = 1500000ll * 1500000;
    struct Vector {
        Vector(LL x = 0, LL y = 0) {
            this->x = x;
            this->y = y;
        }
    
        Vector operator + (const Vector &rhs) const {
            return Vector(x + rhs.x, y + rhs.y);
        }
    
        Vector operator - (const Vector &rhs) const {
            return Vector(x - rhs.x, y - rhs.y);
        }
    
        LL len() {
            return x * x + y * y;
        }
    
        LL x, y, id;
    }a[N];
    
    int main(){
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) {
            scanf("%lld%lld", &a[i].x, &a[i].y);
            id[i] = i;
        }
    
        while(1) {
            random_shuffle(id + 1, id + n);
            Vector now;
            for(int i = n; i >= 1; i--) {
                int pos = id[i];
                Vector nx1 = now + a[pos];
                Vector nx2 = now - a[pos];
                if(nx1.len() <= nx2.len()) {
                    now = nx1;
                    ans[pos] = 1;
                } else {
                    now = nx2;
                    ans[pos] = -1;
                }
            }
    
            if(now.len() <= base) {
                for(int i = 1; i <= n; i++) {
                    printf("%d ", ans[i]);
                }
                puts("");
                return 0;
            }
        }
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    Python3网络学习案例三:编写web server
    struct.pack()和struct.unpack() 详解(转载)
    Python3网络学习案例二:traceroute详解
    Redis 配置
    vue之this.$route.params和this.$route.query的区别
    解决bugs: mybatisPlus 分页不能生效
    解决bug :"status":400,"error":"Bad Request","message":"Required request body is missing:
    vue,ElementUI中Switch 开关,switch 打开时的值为数字,该如何设置
    解决bug:vue项目中点击修改按钮,不能显示要修改的分类名字
    The 'Access-Control-Allow-Origin' header contains multiple values'*, *', but only one is allowed.
  • 原文地址:https://www.cnblogs.com/CJLHY/p/9224899.html
Copyright © 2020-2023  润新知