2 条题解
-
1徐静雨 (xujingyu) LV 8 @ 2023-6-21 21:09:13
debug了半小时,结果发现......
想引用一下
曾经最近没开时写的:不过数据范围我数组开到评测只因你告诉我
Standard answer longer than user output.
...得了正题。
用个动态数组,是局部的,每次存删除后的水果序列,再赋值给最终的。
code:
#include <bits/stdc++.h> using namespace std; int n,a[300000],l[300000],r[300000];//报复性开大 vector <int> ve; vector <int> tmp; signed main() { freopen("fruit.in","r",stdin); freopen("fruit.out","w",stdout); scanf("%d",&n); a[0] = a[n + 1] = -1; r[0] = 1; l[n + 1] = n; for(int i = 1;i <= n;i++) { scanf("%d",&a[i]); if(a[i] != a[i - 1]) ve.push_back(i); l[i] = i - 1; r[i] = i + 1; } while(r[0] != n + 1) { tmp.clear(); for(int i = 0;i < ve.size();i++) { printf("%d ",ve[i]); int u = l[ve[i]]; int v = r[ve[i]]; r[u] = v; l[v] = u; if(a[ve[i]] != a[u] && a[ve[i]] == a[v]) tmp.push_back(v); } ve = tmp; printf("\n"); } return 0; }
-
02023-9-29 13:34:56@
#include <iostream> #include <cstdio> #include <vector> using namespace std;
struct block { int value; int count; int begin; };
int main() { int n = 0; scanf("%d", &n);
vector<block> myblocks; int intput = 0; for (int i=1; i<=n; i++) { scanf("%d", &intput); if (0 == myblocks.size()) { block first_block; first_block.value = intput; first_block.count = 1; first_block.begin = i; myblocks.push_back(first_block); } else { block &cur_block = myblocks.back(); if (intput == cur_block.value) { cur_block.count++; } else { block new_block; new_block.value = intput; new_block.begin = i; new_block.count = 1; myblocks.push_back(new_block); } } } while (0 != myblocks.size()) { vector<block>::iterator iter = myblocks.begin(); int cur_value = -1; while (iter != myblocks.end()) { if (0==(*iter).count) { iter = myblocks.erase(iter); continue; } else { if (cur_value != (*iter).value) { cout << (*iter).begin << ' '; cur_value = (*iter).value; (*iter).begin++; (*iter).count--; } iter++; } } cout << endl; } return 0;
}
- 1
信息
- ID
- 1478
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 22
- 已通过
- 3
- 上传者