zoukankan      html  css  js  c++  java
  • [CF576C] Points on Plane

    [CF576C] Points on Plane - 莫队

    Description

    给出(N)个整点((x_i,y_i)),求一个排列(p_i),使得(sumlimits_{i=2}^N |x_{p_i} - x_{p_{i-1}}| + |y_{p_i} - y_{p_{i-1}}| leq 2.5 imes 10^9)

    Solution

    这个要求让人想到莫队

    加上奇偶优化刚好能过

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    const int siz = 1e3;
    
    signed main()
    {
        ios::sync_with_stdio(false);
    
        int n;
        cin >> n;
    
        struct point
        {
            int x, y, id;
            bool operator<(const point &rhs)
            {
                int block = x / siz;
                int block_rhs = rhs.x / siz;
                if (block != block_rhs)
                    return block < block_rhs;
                if (block & 1)
                    return y < rhs.y;
                else
                    return y > rhs.y;
            }
        };
    
        vector<point> vec(n);
        for (int i = 0; i < n; i++)
        {
            cin >> vec[i].x >> vec[i].y;
            vec[i].id = i + 1;
        }
    
        sort(vec.begin(), vec.end());
    
        for (int i = 0; i < n; i++)
        {
            cout << vec[i].id << " ";
        }
    }
    
  • 相关阅读:
    12.Scala- 注解
    11.Scala-特质
    10.Scala-继承
    9.Scala- 包和引入
    8.Scala-对象
    7.Scala-类
    6.Scala-高阶函数
    5.Scala-匹配模式
    4.Scala-数据结构
    Ruby on Rails Tutorial 第四章 Rails背后的Ruby 之 类
  • 原文地址:https://www.cnblogs.com/mollnn/p/14445270.html
Copyright © 2011-2022 走看看