Title Description
Input Format
output Format
Output to File Earthworm.out
The first line outputs [m/t] integers, in chronological order, output t seconds, 2t seconds, 3t seconds ... The length of the worm being cut off (before being cut off).
Sample Data Sample Input
Input Sample # #:
3 7 1 1 3 1
3 3 2
Input Sample #:
3 7 1 1 3 2
3 3 2
Input Sample # #:
3 7 1 1 3 9
3 3 2 sample output
Sample # # of output:
3 4 4 4 5 5 6
6 6 6 5 5 4 4 3 2 2
Output Example #:
4 4 5
6 5 4) 3 2
Output Sample # #:
Blank Line
2 Description
"Sample Interpretation 1"
Before the sword hand arrives: the length of 3 earthworms is 3,3,2.
After 1 seconds: a 3-length earthworm was cut into two earthworms of 1 and 2 lengths, and the remaining earthworms increased by 1 in length. The length of the final 4 earthworms was (4), 3, respectively. The parentheses indicate that this position has just been severed by an earthworm.
After 2 seconds: a 4-length earthworm was cut into 1 and 3. The lengths of 5 earthworms were: 2, 3, (1,3), 4.
After 3 seconds: an earthworm with a length of 4 is cut off. The lengths of 6 earthworms were: 3,4,2,4, (1,3).
After 4 seconds: an earthworm with a length of 4 is cut off. The lengths of 7 earthworms were: 4, (1,3), 3,5,2,4.
After 5 seconds: an earthworm with a length of 5 is cut off. The lengths of 8 earthworms were: 5,2,4,4, (1,4), 3, 5.
After 6 seconds: an earthworm with a length of 5 is cut off. The lengths of 9 earthworms were: (1,4), 3,5,5,2,5,4,6.
After 7 seconds: an earthworm with a length of 6 is cut off. The lengths of 10 earthworms were: 2,5,4,6,6,3,6,5, (2,4). So, the length of the earthworm that was cut off in 7 seconds was 3,4,4,4,5,5,6. After 7 seconds, all earthworm lengths are sorted from large to small to 6,6,6,5,5,4,4,3,2,2
"Sample Interpretation 2"
Only t=2 in this data is different from the previous data. You only need to output one number per two numbers per line.
Although the first line has a 6 that is not output, the second row still needs to be re-exported from the second number.
"Sample Interpretation 3"
Only t=9 in this data is different from the previous data.
Note that the first row has no number to output, but also to output a blank line.
Problem Analysis
Normal idea: Heap + offset (This is more cumbersome to write than positive solution ...)
Estimated score: 80 points
Positive solution:
Open three queues, the first queue storage is not cut earthworms, the second queue is cut off the first half of the Earthworm, the third queue to store the cut half of the worm.
Sort the first queue in advance to make sure all queues are ordered (think about why.) The
removes one of the largest cuts from three queues at a time and adds the offset delta to the delta, of course, to ensure that the elements in the queue are reduced by deltas. Why does the
need to introduce an offset delta? Because we want to keep the queue in order, if the manual sort is nlogn, it becomes violent, so delta is needed to maintain the queue indirectly.
Note to open a long long. Source Code
#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include < cstdlib> #include <vector> #include <cstdio> #include <cmath> #include <queue> using
namespace Std;
inline const int Get_int () {int num=0,bj=1;
Char X=getchar (); while (x< ' 0 ' | |
X> ' 9 ') {if (x== '-') bj=-1;
X=getchar ();
} while (x>= ' 0 ' &&x<= ' 9 ') {num=num*10+x-' 0 ';
X=getchar ();
} return NUM*BJ;
} BOOL CMP (long long A,long long b) {return a>b;} int n,m,q,u,v,t,cnt=0;
Long Long a[8000005],delta=0;
Deque<long long>q[4];
int main () {n=get_int ();
M=get_int ();
Q=get_int ();
U=get_int ();
V=get_int ();
T=get_int ();
for (int i=1; i<=n; i++) a[i]=get_int ();
Sort (a+1,a+n+1,cmp);
for (int i=1; i<=n; i++) Q[1].push_back (A[i]);
for (int i=1; i<=m; i++) {Long long max=-1e10,maxl; for (int j=1; j<=3; J + +) if (! Q[J].empty () &&q[j].front () >max) {Max=q[j].front ();
Maxl=j;
} q[maxl].pop_front ();
Max+=delta;
if (i%t==0) printf ("%lld", Max);
delta+=q;
Long Long left=max*u/v,right=max-left;
Q[2].push_back (Left-delta);
Q[3].push_back (Right-delta);
} putchar (' \ n '); while (! Q[1].empty () | |! Q[2].empty () | |!
Q[3].empty ()) {cnt++;
Long Long Max=-1e10,maxl; for (int i=1; i<=3; i++) if (!
Q[i].empty () &&q[i].front () >max) {Max=q[i].front ();
Maxl=i;
} Max+=delta;
if (cnt%t==0) printf ("%lld", Max);
Q[maxl].pop_front ();
} return 0;
}