Egypt score IDS Search Vijos 1308

Source: Internet
Author: User

Transmission Door
Search Package The second iteration deepens
Compared to the classic because of his search layer in time and space is unknown
So we can give him a predetermined number of layers to search for.
If there is no optimal solution at this level
Then jump to the next level and search.

For each layer of search attention pruning
First is the feasibility of pruning for this number if the number is greater than the desired so t drop the point
If the number multiplied by three is less than the desired t-drop point
Pay attention to the properties of fractions note-Pass
Note the requirement of minimum dictionary order
Spit it out, the data is slightly weak.
Below is a slightly slower AC code to optimize

#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace STD;Long Longs[ -],ans[ -],sr,ar;structscore{Long LongUp,down; Score () {} score (Long LongXLong LongY): Up (x), X=X/__GCD (y) {x, y), y=y/__gcd (x, y);}DoubleCalc () {return 1.0*up/down;}}; Scoreoperator-(score A,score B) {Long LongTmp1=a.up,tmp2=a.down,tmp3=b.up,tmp4=b.down;    Tmp1*=tmp4,tmp3*=tmp2;tmp1-=tmp3; Tmp2*=tmp4;Long LongK=__GCD (TMP1,TMP2);    Tmp1/=k,tmp2/=k; Score C (TMP1,TMP2);returnC;}BOOL operator< (score A,score B) {returnA.calc () < B.calc ();} Scoreoperator*(intX,score B) {score C (B.up*x,b.down);returnC;}intTotBOOLcmp=false;voidCheck () {Long LongTmp1=sr,tmp2=ar;if(!ar) { for(intI=1; i<=sr;++i) ANS[I]=S[I];AR=SR;return;}if(S[TMP1]&GT;ANS[TMP2])return;if(S[TMP1]&LT;ANS[TMP1]) { for(intI=1; i<=sr;++i) ans[i]=s[i];return;} tmp1=1; while(ANS[TMP1]==S[TMP1]) tmp1++;if(ANS[TMP1]&GT;S[TMP1]) for(intI=tmp1;i<=sr;++i) ans[i]=s[i];}voidPut () { for(intI=1; i<ar;++i)printf("%lld", Ans[i]);printf("%lld", Ans[ar]);}voidDFS (Score A,intDepthintXintwould) {if(Depth >= would) {if(a.up==1) {S[++sr]=x;s[++sr]=a.down;if(s[sr]==s[sr-1]) {sr-=2;return;} Check (); sr-=2; cmp=true;}return;}if(1.0* (will-depth+1)/x<a.calc ())return;Doubletmp=1.0* (will-depth+1)/a.calc (); for(inti=x+1; tmp>i;++i) {Score C (1, i);if(A&LT;C)Continue; Score tmp (1, i); Score b=a-tmp;if(depth>1) S[++sr]=x; DFS (b,depth+1, I,will);if(depth>1)--SR; }}intMain () {intb;Cin>>a>>b; Score A (A, b);intCNT =0; while(1) {cnt++; DFS (A,1,1, CNT);if(CMP) {put ();return 0;} }   }

Egypt score IDS Search Vijos 1308

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.