1、题意:题意有些难理解



2、分析:我们发现如果要求判断是否合法的话就so easy了,二分图匹配即可,但是我们发现要求输出字典序最小的,那么我们在匈牙利的时候就倒着枚举,另外邻接表中的边一定要排好序,如果用的是链表的话,就从大到小,vector就从小到大插入,然后我们就可以保证字典序最小了,想了半天网络流QAQ,看了题解。。匈牙利是啥都快忘记了。。。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define M 20010

inline int read(){
    char ch = getchar(); int x = 0, f = 1;
    while(ch < '0' || ch > '9'){
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while('0' <= ch && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
} 

struct Edge{
    int u, v, next;
} G[M];
int head[M], tot;
int tim;
int pre[M], vis[M];

inline void add(int u, int v){
    G[++ tot] = (Edge){u, v, head[u]};
    head[u] = tot;
}

inline bool dfs(int u){
    for(int i = head[u]; i != -1; i = G[i].next){
        if(vis[G[i].v] != tim){
            vis[G[i].v] = tim;
            if(pre[G[i].v] == -1 || dfs(pre[G[i].v])){
                pre[G[i].v] = u;
                pre[u] = G[i].v;
                return 1;
            }
        }
    }
    return 0;
}

int main(){
    memset(head, -1, sizeof(head));
    memset(pre, -1, sizeof(pre));
    int n = read();
    for(int i = 1; i <= n; i ++){
        int d = read();
        int a = i - d, b = i + d;
        if(a <= 0) a += n;
        if(b > n) b -= n;
        a += n; b += n;
        if(a < b) swap(a, b);
        add(i, a); add(i, b);
    }
    for(int i = n; i >= 1; i --){
        tim ++;
        if(!dfs(i)){
            printf("No Answer");
            return 0;
        }
    }
    for(int i = 1; i < n; i ++) printf("%d ", pre[i] - n - 1);
    printf("%d\n", pre[n] - n - 1);
    return 0;
} 

最新文章

  1. 5Hibernate配置及使用方法----青软S2SH(笔记)
  2. 【iCore3 双核心板】例程十三:SDIO实验——读取SD卡信息
  3. 动画---图形图像与动画(三)Animation效果的XML实现
  4. HTML相对路径 当前目录、上级目录、根目录、下级目录表示法
  5. Format可能存在的坑
  6. 去掉IntelliJ IDEA的拼写检查
  7. tomcat启动报错:Unsupported major.minor version 51.0
  8. Java学习----不变的常量
  9. 属性动画 LayoutTransition AnimatorInflater Keyframe 新特性
  10. Spring之SpringMVC的RequestToViewNameTranslator(源码)分析
  11. Oozie时出现Exception in thread &quot;main&quot; java.lang.UnsupportedClassVersionError: com/mysql/jdbc/Driver : Unsupported major.minor version 52.0?
  12. Oracle 10g 应用补丁PSU 10.2.0.5.180717
  13. HTTP &amp;RFC
  14. git 和github使用
  15. PHP之魔术方法
  16. C++拷贝构造函数的调用时机
  17. python使用SAX解析xml
  18. ArcGIS案例学习笔记2_2_模型构建器和山顶点提取批处理
  19. mfc Edit控件属性
  20. 撩课-Web大前端每天5道面试题-Day8

热门文章

  1. thinkphp
  2. Java开发环境的搭建以及使用eclipse从头一步步创建java项目
  3. K-means聚类算法
  4. Java使用代理服务器
  5. 【JavaScript】javascript 方法 test()
  6. C# 使用网易邮箱发送邮件
  7. Codeforces Round #373 (Div. 2)
  8. windows下 nvm下载node被墙了解决办法
  9. 【整理】认识MSG结构体
  10. Linux 下EXT2文件系统 —— 如何将蚂蚁和大象优雅的装进冰箱里