Systematic training, inspirational challenge Programming Competition-code sorting 103 ~ 134 [preliminary]

Source: Internet
Author: User

Systematic training, inspirational challenge Programming Competition-code sorting 103 ~ 134 [preliminary]

In September 6, 2014, I got it here. I have finished the preliminary refresh and stopped it first. I read the directory in the intermediate article. I used to refresh it all before, but I don't have a system refresh. I want to refresh it several days later, let's take a look at the java interview book. It is expected to take 10 days to complete. Region ~

/**/# Include
 
  
Using namespace std;/* gcd phase division, Euclidean Algorithm for Solving points on a straight line, cut the smallest square */int gcd (int x, int y) {return y = 0? X: gcd (y, x % y);}/* extgcd, extends the Euclidean algorithm to solve the integer solution of the binary one equation. ax + by = c returns the solution c on the Right of function =: int a declares an int type. The name is aint * a. It declares an int pointer type. The name is aint & a. It declares an int reference type and the name is a */int extgcd (int, int B, int & x, int & y) {int d = a; if (B! = 0) {d = extgcd (B, a % B, y, x); y-= (a/B) * x;} else {x = 1; y = 0;} return d;}/* Fast Power Operation x ^ n mod m */typedef long ll; ll mod_pow (ll x, ll n, ll m) {int res = 1; while (n> 0) {if (n & 1) res = res * x % m; // if n is an odd number, if the original formula is multiplied by x ^ (2 ^ 1), then res * x % mx = x * x % m; n> = 1; // n/2} return res ;} /* modulo n mod m1234 = (1*10 + 2) * 10 + 3) * 10) + 4 // mod m in each bracket once, accumulate: */void big_mod () {char n [100]; int m; scanf ("% s % d", n, & m ); int len = strlen (n); int ans = 0; for (int I = 0; I
  
   


/* Sort all edge weights from small to large to determine whether the two nodes of the edge are in the same connected component. If not, merge the MST. */# Include
    
     
Using namespace std; const int MAXN = 1 <10; struct edge {int u, v, cost ;}; edge es [MAXN]; int V, E; int par [MAXN], rank [MAXN]; int comp (const edge & e1, const edge & e2) {return e1.cost
     
      
Rank [B]) par [a] = B; else {par [B] = a; if (rank [a] = rank [B]) rank [a] ++ ;}} int kruskal () {sort (es, es + E, comp); init (V); int res = 0; for (int I = 0; I
      
       

/* And dijikstra algorithm */# include
        
         
Using namespace std; const int MAXN = 1 <10; int mincost [MAXN], cost [MAXN] [MAXN]; // mincost [I], minimum bool used [MAXN]; int V; int INF = (1 <31)-1; int prim () {fill (mincost, mincost + V, INF); fill (used, used + V, false); mincost [0] = 0; int res = 0; while (true) {int v =-1; // select the smallest weight point in non-x for (int I = 0; I
         
          

/* Dijkstra algorithm, selects the smallest vertex d to update the edge, that is, edge adding is suitable for graph problems without negative weight */# include
           
            
# Include
            
             
# Include
             
              
Using namespace std; const int MAXN = 1 <10; int cost [MAXN] [MAXN]; // weight of u-> v int V, d [MAXN], INF = (1 <31)-1; bool used [MAXN]; int prev [MAXN];/* d [v], cost [u] [v] to store */void pair stra1 (int s) {fill (d, d + V, INF); fill (used, used + V, false ); fill (prev, prev + V,-1); d [0] = 0; while (true) {int v =-1; // select an unused minimum vertex for (int u = 0; u
              
               
Get_path (int t) {vector
               
                
Path; for (; t! =-1; t = prev [t]) path. push_back (t); reverse (path. begin (), path. end (); return path;}/* uses the adjacent table + heap [minimum search], complexity ElogV */struct edge {int to, cost;}; vector
                
                  G [MAXN]; typedef pair
                 
                   P; // first indicates the shortest distance, and second indicates the vertex number void pair stra2 (int s) {priority_queue
                  
                    , Greater
                   

> Que; fill (d, d + V, INF); que. push (P (0, s); // initialize while (! Que. empty () {P p = que. top (); que. pop (); int v = p. second; // retrieve the number if (d [v]

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.