zoukankan      html  css  js  c++  java
  • Gym

    题意:n个传送带,传送带i运送编号为i的物品,机器人可以负责把传送带i上的物品放到传送带i + 1上,也可以把传送带i + 1上的物品放到传送带i上,机器人分布在传送带上x轴的不同位置,问每个传送带最多能传送多少物品。

    分析:

    1、将机器人按x轴排序。

    2、对于每个传送带,记录它能传送的最小的传送带编号和能传送的最大的传送带编号即可。

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define Min(a, b) ((a < b) ? a : b)
    #define Max(a, b) ((a < b) ? b : a)
    const double eps = 1e-12;
    inline int dcmp(double a, double b)
    {
        if(fabs(a - b) < eps) return 0;
        return a > b ? 1 : -1;
    }
    typedef long long LL;
    typedef unsigned long long ULL;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
    const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const int MAXN = 200000 + 10;
    const int MAXT = 3025 + 10;
    using namespace std;
    struct Node{
        int x, id;
        void read(){
            scanf("%d%d", &x, &id);
        }
        bool operator < (const Node&rhs)const{
            return x < rhs.x;
        }
    }num[MAXN];
    int l[MAXN], r[MAXN];
    int main(){
        int n, m;
        scanf("%d%d", &n, &m);
        for(int i = 0; i < m; ++i){
            num[i].read();
        }
        for(int i = 1; i <= n; ++i){
            l[i] = i;
            r[i] = i;
        }
        sort(num, num + m);
        for(int i = 0; i < m; ++i){
            int y = num[i].id;
            l[y] = l[y + 1] = min(l[y], l[y + 1]);
            r[y] = r[y + 1] = max(r[y], r[y + 1]);
        }
        for(int i = 1; i <= n; ++i){
            if(i != 1) printf(" ");
            printf("%d", r[i] - l[i] + 1);
        }
        printf("
    ");
        return 0;
    }
    

      

  • 相关阅读:
    P2572 [SCOI2010]序列操作
    P2787 语文1(chin1)- 理理思维
    P1835 素数密度_NOI导刊2011提高(04)
    P3942 将军令
    P1273 有线电视网
    U45490 还没想好名字的题Ⅱ
    U40620 还没想好名字的题
    P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚
    P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
    T51071 Tony到死都想不出の数学题
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/7467157.html
Copyright © 2011-2022 走看看