题意: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("\n"); return 0; }
时间: 2024-10-07 10:55:56