title: http://www.tsinsen.com/A1504A1504. Book (DI) time limit:1.0s Memory limit:256.0MB Special Judge Total number of commits:
359AC Times:
theAverage score:
43.76Share this topic: View unformatted question submission question source 2013 China National Training Team second homework problem description Wayne likes to read books, he prefers to buy them.
One day Wayne bought books on Dangdang and bought a lot of books. Wayne has a strange hobby, that is, the first book must be the price of x, and then every book bought later, if it is more expensive than the previous one, the price of a maximum of a yuan, if it is cheaper than the previous one, the price of the most B-yuan.
Wayne had a whim to buy N books, but he could not remember the price of every book, only the Total price was M. Wayne would like to know a possible book price distribution. To simplify the problem, we assume that the definition field of the book price is an integer, and that the price difference between each book and the previous book is either +a or just-B.
Just give any valid book price sequence even if it is correct. Input format first line a positive integer n.
The second row of four integers is followed by x,a,b,m. Output format output a row of n integers, separated by a space. Data is guaranteed to be solvable. Sample Input 4
10 1 2 37 Sample output 10 11 9 7 data size and conventions for the data of 5%, n = 1 is satisfied.
For another 25% of the data, a = B = 1, N <= 100 is satisfied.
For another 10% of the data, meet a, B <= 5, N <= 100.
For another 20% of the data, N <= 1000 is satisfied.
For 100% of data, meet 1 <= A, B <= 10^6,| X| <= 10^6,n <= 10^5,m can be used with signed 64-bit integer storage.
To submit a question for discussion: number theory + greed The following is Di's Problem solving report:
1#include <bits/stdc++.h>2 using namespacestd;3 #defineLL Long Long4 //LL prey[100010];5 BOOLvis[100010];6 LL Read ()7 {8LL s=0, fh=1;CharCh=GetChar ();9 while(ch<'0'|| Ch>'9'){if(ch=='-') fh=-1; ch=GetChar ();}Ten while(ch>='0'&&ch<='9') {s=s*Ten+ (ch-'0'); ch=GetChar ();} One returns*fh; A } - intMain () - { the LL N,X,A,B,M,K,I,J,LP; -n=read (); -X=read (); A=read (); B=read (); m=read (); -K=n*x+ ((n1) *n)/2*a;//Suppose all the total amount of a is increased. +K-=m;//Subtract (a+b) The amount of money that is converted from +a to-B by adding the total amount of a, minus the actual cost. -K/= (A+B);//calculates how many books have been converted from +a to-B. + //because each difference is changed, the number of affected numbers is one of (0,1,2...n-1). So we just need to ask that the K can be made up of 0~ (n-1). Amemset (Vis,false,sizeof(Vis)); at for(i=n-1; i>=0; i--)//to look backwards, make sure K can be composed. (somewhat analogous to the inverted-looking principle of multiplying the LCA) - { - if(k>=i) - { -k-=i; -vis[i]=true;//a delegate marked as true is to be converted to-B. in if(k==0) Break; - } to } + /*Double cycle (60 points) - For (i=1;i<=n;i++) {prey[i]=x;x+=a;} the For (i=1;i<=n-1;i++) * { $ if (vis[i]==true)Panax Notoginseng { - For (j=n;j>=n-i+1;j--) prey[j]-= (a+b); the } + } A for (i=1;i<=n;i++) printf ("%lld", Prey[i]);*/ theprintf"%lld", x); + for(i=n-1; i>=1; i--) - { $ if(vis[i]==true)//to convert to-B, add-B (that is, minus B) on the basis of the original X. $ { -x-=b; - } the Else - {Wuyix+=A; the } -printf"%lld", x); Wu } - fclose (stdin); About fclose (stdout); $ return 0; -}
Tsinsen A1504. Book (DI) number theory, greed