bzoj1562: [NOI2009] Transform sequence

Source: Internet
Author: User

Hungary matches.

Each edge in the adjacency table is sorted in ascending order of destination. Augmented from the last point of X so that each point matches the smallest of the dictionary orders first, and if the previous point does not find a match, the subsequent points match to a slightly larger Y-match point.

Map Description: Each point has and will only have two points to meet the distance requirements, you can think about why.

The y point is to be +n with the X point.

#include <cstdio>#include<algorithm>#include<cstring>#include<vector>using namespacestd;Const intMAXN =30000+Ten; Vector<int>G[MAXN];BOOLVIS[MAXN];intP[MAXN];intN;BOOLFindintu) {if(Vis[u])return false; Vis[u]=true;  for(intI=0, V;i<g[u].size (); i++) {v=G[u][i]; if(!p[v] | |find (P[v])) {P[v]=u; P[u]=v; return true; }    }    return false;}intMain () {scanf ("%d",&N);  for(intI=0, d;i<n;i++) {scanf ("%d",&d); intA= (i+d)%n,b= (i+n-d)%N; if(a>b) Swap (A, a); G[i].push_back (A+N); G[i].push_back (b+N); }     for(inti=n-1; i>=0; i--) {memset (Vis,0,sizeof(VIS)); if(!find (i)) {printf ("No Answer"); return 0; }    }     for(intI=0; i<n;i++)if(i) printf ("%d", p[i]-N); Elseprintf"%d", p[i]-N); return 0;}

bzoj1562: [NOI2009] Transform sequence

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.