"Uoj264" noip2016-earthworms

Source: Internet
Author: User

http://uoj.ac/problem/264 (Topic link)

Test instructions

N Earthworms, Time is M. Each unit of time to be able to cut the longest earthworm into LEN/2 and LEN-LEN/2 two parts, the length of 0 earthworms will not disappear, because every unit of time all the length of the earthworm will grow L. When time t is a multiple of T, output the length of the worm that is currently about to be cut, and after completion of the cut, the output is sequentially outputting the length of the earthworm in multiples of T.

Solution

We build 3 monotone queues, which are recorded as q[0],q[1],q[2]. where q[0] records the length of each earthworm at the beginning and arranges it in order from large to small. Q[1] Records the length of the cut that is long after each cutting. Q[2] Records the length of the short section after each cut. For the length of earthworm growth, we can use the idea of labeling, because each earthworm grows the same length.

Obviously, the structure of the 3 queues are monotonically decreasing, so each cut, take 3 teams queue the first largest element to cut, assuming its size is x, the current growth length of L, per unit of time earthworm length growth L. So, the length of the earthworm is len=x+l, the cut length is recorded as L1 and L2, then the L1 and L2 are subtracted l+l when placed in the queue, so that they can be synchronized with the tag of the element in the entire queue.

When the output is needed, determine if the current time is a multiple of T.

Details

Do not use double when cutting, precision is too withered, uoj on the hack.

Code
uoj264#include<algorithm> #include <iostream> #include <cstring> #include <cstdlib># include<cstdio> #include <cmath> #include <queue> #define LL long long#define RG register#define inf 2147483640#define Pi ACOs ( -1.0) #define FREE (a) freopen (a ".", "R", stdin), Freopen (a ". Out", "w", stdout); using namespace Std;inline int gi () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | | ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ( );} while (ch>= ' 0 ' && ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} const int Maxn=100010;int n,m,l,u,v,t;int A[maxn];int head[3],q[3][10000010],tail[3];inline BOOL cmp (int a,int b) { return a>b;} int main () {N=gi (), M=gi (), L=gi (), U=gi (), V=gi (), T=gi (); memset (q,-0x7f,sizeof (q)); for (int i=1;i<=n;i++) q[0][i]= GI (); sort (q[0]+1,q[0]+1+n,cmp); int l=0;head[0]=head[1]=head[2]=1;tail[0]=tail[1]=tail[2]=0;tail[0]=n;for (int x), l1,l2,op,i=1;i<=m;i++) {op=q[0][head[0]]>q[1][head[1]]? 0:1;op=q[op][head[op]]>q[2][head[2]]? OP: 2;x=q[op][head[op]++]+l;if (i%t==0) printf ("%d", x); l1= (LL) X*u/v;l2=x-l1;q[1][++tail[1]]=max (L1,L2)-l-l;q[2][++ Tail[2]]=min (L1,L2)-l-l;l+=l;} Puts (""); for (int x,op,i=1;i<=n+m;i++) {op=q[0][head[0]]>q[1][head[1]]? 0:1;OP=Q[OP][HEAD[OP]]&GT;Q[2][HEAD[2]]? Op:2;x=q[op][head[op]++]+l;if (i%t==0) printf ("%d", x);} return 0;}

  

"Uoj264" noip2016-earthworms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.