BZOJ4029[HEOI2015] Pricing

Source: Internet
Author: User

http://www.lydsy.com/JudgeOnline/problem.php?id=4029

Greedy.

Enumeration of how many after 0 (it may be enumerated to have K 0), find the first $10^k$ greater than or equal to the multiple, and the first $5*10^k$ greater than equal to the odd number of times, only these 2 can be the answer.

Then choose the best from it.

#include <cstdio>#include<cstdlib>#include<iostream>#include<fstream>#include<algorithm>#include<cstring>#include<string>#include<cmath>#include<queue>#include<stack>#include<map>#include<utility>#include<Set>#include<bitset>#include<vector>#include<functional>#include<deque>#include<cctype>#include<climits>#include<complex>//#include <bits/stdc++.h> for Cf,uoj, but not for POJ using namespaceStd;typedefLong LongLl;typedefDoubleDb;typedef pair<int,int>Pii;typedef Complex<DB>CP;#defineMmSt (a,v) memset (A,v,sizeof (a))#defineMmcy (A, B) memcpy (A,b,sizeof (a))#defineFill (a,l,r,v) Fill (a+l,a+r+1,v)#defineRe (I,A,B) for (i= (a); i<= (b); i++)#defineRed (i,a,b) for (i= (a); i>= (b); i--)#defineIRE (I,X) for (typedef (X.BEGIN ()) I=x.begin (); I!=x.end (); i++)#defineFi first#defineSe Second#defineM_p (A, B) Make_pair (A, B)#defineP_b (a) push_back (a)#defineSF scanf#definePF printf#defineBoth (k) (1<< (k))Template<classT>inline T Sqr (t x) {returnx*x;} Template<classT>inlinevoidUpmin (T &t,t tmp) {if(t>tmp) t=tmp;} Template<classT>inlinevoidUpmax (T &t,t tmp) {if(t<tmp) t=tmp;}ConstDB eps=1e-9; inlineintSGN (DB x) {if(ABS (x) <eps)return 0;return(x>0)?1:-1;}ConstDB Pi=acos (-1.0); inlineintGint () {intres=0;BOOLneg=0;CharZ;  for(Z=getchar (); z!=eof && z!='-'&&!isdigit (z); z=GetChar ()); if(z==eof)return 0; if(z=='-') {neg=1; z=GetChar ();}  for(; z!=eof && isdigit (z); res=res*Ten+z-'0', z=GetChar ()); return(neg)?-Res:res; }inline ll Gll () {ll res=0;BOOLneg=0;CharZ;  for(Z=getchar (); z!=eof && z!='-'&&!isdigit (z); z=GetChar ()); if(z==eof)return 0; if(z=='-') {neg=1; z=GetChar ();}  for(; z!=eof && isdigit (z); res=res*Ten+z-'0', z=GetChar ()); return(neg)?-Res:res; }Const intinf=0x3f3f3f3f; LL A,b,ans;intX;inlineintCol (LL v) {intres=0;  while(v%Ten==0) v/=Ten; if(v%Ten==5) res--;  while(v!=0) v/=Ten, res+=2; returnRes; }inlinevoidDFS (LL div) {intC= (A-1)/div+1) *div,dc=Col (C); intD= ((A-1)/(5*DIV) +1) &1) ? (A-1)/(5*DIV) +1)*(5*div): ((A-1)/(5*DIV) +1+1)*(5*DIV), dd=Col (D); if(C&GT;B)return; if(d>b) dd=INF; if(dc<x) x=dc,ans=b; if(dd<x) x=dd,ans=e; DFS (Div*Ten); }intMain () {Freopen ("bzoj4029.in","R", stdin); Freopen ("Bzoj4029.out","W", stdout);  for(intCase=gint (); case; case--) {cin>>A>>C; X=INF; DFS (1); cout<<ans<<Endl; }      return 0; }
View Code

BZOJ4029[HEOI2015] Pricing

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.