Bzoj 1151 proud people sort of

Source: Internet
Author: User

a proud man.

Time Limit:1 Sec

Memory limit:256 MB

Topic Connection http://acm.uestc.edu.cn/#/problem/show/1151
Description

YesNA proud person, you have to appoint them to finish the work.只有当现在被指派的人完成了工作,你才能指派下一个。It takes everyone to finish the workTi Minutes, but! They're all so proud that they want you to appoint him right away, if you procrastinate. t minutes to assign him, then you need to pay him T-Ci yuan as compensation. Q, how many dollars will it cost to assign all the proud people?

Input

First line input an integer n (1≤n≤5)

Enter four seed numbers in the second rowA,B,C,D  (1≤ a, b, c, d≤10007) 。 You need to get through these 4 seed numbers Ti and Ci, the method is as follows:

Const IntMoD=10007;typedef Long Longll;voidGetData(IntA,IntB,IntC,IntD,IntN,Int *T,Int *C){T[0]=C[0]=0; For(IntI=1;I<=N;I++){T[i]= (t[i -1]*a+ b)%mod+1  C[i]= (c [i-1]* c+d)%mod +1; }}          /span>                 
Output

The first line outputs an integer representing the minimum amount of money needed to appoint these proud people.

The second line outputs N integers, indicating which person to assign each time, that is, the number of the assigned person is output in the assigned order. For example, there are 5 people, assigned to them sequentially, then output "1 2 3 4 5".如果有多解,输出字典序最小解。

Sample Input51 1 1 1

Sample Output

340 1 2 3 4 5HINT

Test instructions

Exercises

It's just a sequence.

Each value for the subsequent contribution is t[i]* other c[i]

And then, according to this sort, yell.

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<bitset>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 200500#defineMoD 10007#defineEPS 1e-9#definePi 3.1415926intNum;//const int INF=0X7FFFFFFF;Constll inf=999999999; inline ll read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//*************************************************************************************ll T[maxn];ll C[MAXN];structnode{ll x, y, Z; FriendBOOL operator< (ConstNode & A,ConstNode &b) {if(a.x*b.y<a.y*b.x)return true; Else if(a.x*b.y==a.y*b.x && a.z<b.z)return true; return false; }};node ANS[MAXN];intMain () {intn=read (); intA=read (), B=read (), C=read (), d=read ();  for(intI=1; i<=n;i++) {ans[i].z=i; ans[i].x= (ans[i-1].X*A+B)%mod+1; Ans[i].y= (ans[i-1].Y*C+D)%mod+1; } sort (ans+1, ans+1+N); LL now=0, Ans =0;  for(intI=1; i<=n;i++) Ans+ = Now * Ans[i].y,now + =ans[i].x; printf ("%lld\n", Ans);  for(intI=1; i<=n;i++)    {        if(i==1) printf ("%d", ans[i].z); Elseprintf ("%d", ans[i].z); } printf ("\ n");}

Bzoj 1151 proud people sort of

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.