[SCU4443] Range Query [2015 Sichuan Province Contest Final H]
来源:互联网 发布:网络诈骗支付宝转账 编辑:程序博客网 时间:2024/05/22 08:03
题意
求一个排列,使得限制成立。限制形如[l,r]之间最大值或最小值是几
题解
按照字典序枚举每一位,枚举到某一位时用最大匹配判定此时是否有解,有解则可以进行下一位的确定
代码
/****************************************\* Author : ztx* Title : H - Range Query* ALG : 完备匹配+最小字典序* CMT : 最大匹配判定+从小到大枚举* Time :\****************************************/#include <cstdio>#define Rep(i,l,r) for(i=(l);i<=(r);i++)#define rep(i,l,r) for(i=(l);i< (r);i++)#define Rev(i,r,l) for(i=(r);i>=(l);i--)#define rev(i,r,l) for(i=(r);i> (l);i--)typedef long long ll ;typedef double lf ;int CH , NEG ;template <typename TP>inline void read(TP& ret) { ret = NEG = 0 ; while (CH=getchar() , CH<'!') ; if (CH == '-') NEG = true , CH = getchar() ; while (ret = ret*10+CH-'0' , CH=getchar() , CH>'!') ; if (NEG) ret = -ret ;}template <typename TP>inline void readc(TP& ret) { while (ret=getchar() , ret<'!') ; while (CH=getchar() , CH>'!') ;}template <typename TP>inline void reads(TP *ret) { ret[0]=0;while (CH=getchar() , CH<'!') ; while (ret[++ret[0]]=CH,CH=getchar(),CH>'!') ; ret[ret[0]+1]=0;}#include <cstring>#define maxn 55LLint n , m1 , m2 ;int matched[maxn] , yx[maxn] ;bool g[maxn][maxn] , vis[maxn] ;bool augment(int u) { for (int v = 1; v <= n; v ++ ) if (g[u][v] && !matched[v] && !vis[v]) if (vis[v] = true, !yx[v] || augment(yx[v])) return yx[v] = u , true ; return false ;}int main() {int i , j , k , a , b , c , max_match ;// #define READ #ifdef READ freopen(".in" ,"r",stdin ) ; freopen(".out","w",stdout) ; #endif while (scanf("%d%d%d", &n, &m1, &m2) != EOF) { Rep (i,1,n) Rep (j,1,n) g[i][j] = true ; // input min Rep (i,1,m1) { read(a) , read(b) , read(c) ; Rep (j,a,b) rep (k,1,c) g[j][k] = false ; rep (j,1,a) g[j][c] = false ; rev (j,n,b) g[j][c] = false ; } // input max Rep (i,1,m2) { read(a) , read(b) , read(c) ; Rep (j,a,b) rev (k,n,c) g[j][k] = false ; rep (j,1,a) g[j][c] = false ; rev (j,n,b) g[j][c] = false ; } // get max_match memset(matched,0,sizeof matched) ; memset(yx,0,sizeof yx) ; max_match = 0 ; Rep (i,1,n) { memset(vis,0,sizeof vis) ; if (augment(i)) max_match ++ ; } // enumerate if (max_match == n) { Rep (i,1,n) {// enumerate position Rep (j,1,n) {// enumerate matching-number if (!g[i][j] || matched[j]) continue ; matched[j] = true ; memset(yx,0,sizeof yx) ; a = true ; Rep (k,i+1,n) if (memset(vis,0,sizeof vis) , !augment(k)) { a = false ; break ; } if (a) break ; matched[j] = false ; } printf("%d%c", j, i==n ? '\n':' ') ; } } else puts("-1") ; } #ifdef READ fclose(stdin) ; fclose(stdout) ; #else getchar() ; getchar() ; #endif return 0 ;}
0 0
- [SCU4443] Range Query [2015 Sichuan Province Contest Final H]
- [SCU4436] Easy Math [2015 Sichuan Province Contest Final A]
- [SCU4437] Carries [2015 Sichuan Province Contest Final B]
- [SCU4438] Censor [2015 Sichuan Province Contest Final C]
- [SCU4439] Vertex Cover [2015 Sichuan Province Contest Final D]
- [SCU4440] Rectangle[2015 Sichuan Province Contest Final E]
- [SCU4441] Necklace [2015 Sichuan Province Contest Final F]
- [SCU4442] Party [2015 Sichuan Province Contest Final G]
- [SCU4444] Travel [2015 Sichuan Province Contest Final I]
- [SCU4445] Right turn [2015 Sichuan Province Contest Final J]
- 2015 Sichuan Province Contest (Carries)
- Sichuan University Programming Contest 2013 Final (singal)E题
- Sichuan University Programming Contest 2013 Final (Single)F题
- Sichuan University Programming Contest 2013 Final (Single)C题
- Sichuan Province 2012 F Fold The Paper
- Contest - zjnu province training(9)
- Sichuan State Programming Contest 2012 Journey
- Sichuan State Programming Contest 2012 Binary Operations
- 剑指Offer—编程题15(链表中倒数第k个结点)
- poj 1905 Expanding Rods(二分)
- 乐观锁和悲观锁的区别
- word2013 无法撤销解决方法-有效
- ThinkPHP foreach和eq嵌套
- [SCU4443] Range Query [2015 Sichuan Province Contest Final H]
- Codeforces 435D Special Grid
- 【CodeForces】[670D2]Magic Powder - 2
- 自定义控件三部曲之绘图篇(十八)——BitmapShader与望远镜效果
- NGINX负载均衡
- 解决 object references an unsaved transient instance - save the transient instance before flushing
- UVA - 10050 Hartals
- STM32自学笔记——外部中断
- SpringAOP注解方式记录操作日志(操作模块,操作功能,调用方法,主键信息等)支持多笔操作时记录