标签:names string lag isp mem one 注意 bmp algo
【问题描述】
#include<cstring> #include<cstdio> #include<algorithm> #include<iostream> #include<vector> using namespace std; int n; int dis[10005]; int lin[10005]; int ans[10005]; bool f[10005]; vector<int>a[10005]; int flag(int q,int p) { return min(abs(q-p),n-abs(q-p)); } bool dfs(int x) { int l=a[x].size(); for(int i=0;i<l;++i) { if(!f[a[x][i]]) { f[a[x][i]]=1; if(lin[a[x][i]]==-1||dfs(lin[a[x][i]])) { lin[a[x][i]]=x; return true; } } } return false; } int main() { //freopen("a.txt","r",stdin); //freopen("b.txt","w",stdout); //freopen("transform.in","r",stdin); //freopen("transform.out","w",stdout); memset(a,0,sizeof(a)); cin>>n; for(int i=0;i<n;++i) scanf("%d",&dis[i]); for(int i=0;i<n;++i) { int x=i+dis[i]; int y=i+n-dis[i]; x%=n;y%=n; if(flag(x,i)!=dis[i]) x=-1; if(flag(y,i)!=dis[i]) y=-1; if(x>y) swap(x,y); if(x!=-1) a[i].push_back(x); if(y!=-1) a[i].push_back(y); } memset(lin,-1,sizeof(lin)); for(int i=n-1;i>=0;--i) { memset(f,0,sizeof(f)); if(!dfs(i)) { cout<<"No Answer"<<endl; return 0; } } //cout<<123456<<endl; for(int i=0;i<n;++i) ans[lin[i]]=i; for(int i=0;i<n-1;++i) printf("%d ",ans[i]); cout<<ans[n-1]<<endl; return 0; }
【BZOJ1562】【jzyzOJ1730】【COGS409】NOI2009变换序列 二分图匹配
标签:names string lag isp mem one 注意 bmp algo
原文地址:http://www.cnblogs.com/snifemoree/p/6703945.html