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