[可图性判定 Havel-Hakimi定理 构造] Codeforces Gym 100269 NEERC 13 Northern K. Kids in a Friendly Class
2017-04-07 06:55
489 查看
黑点和白点的个数可以从小到大枚举
黑白点之间的连边是显然的
那么对于白点或黑点内部 我们就需要连边使得每个点度数相同
每次选两个剩余度最大的点相连是错误的
反例 6 2
那么应该怎么连 需要Havel-Hakimi定理
由非负数组成的非增序列s:d1,d2,⋯,dn(n≥2,d1≥1)是可图的,当仅当序列s1:d2−1,d3−1,⋅⋅⋅,dd1+1−1,dd1+2,⋯,dn
是可图的。
每次选一个剩余度最大的点,将其与其余度最大的若干个点连接使其度满足要求。
黑白点之间的连边是显然的
那么对于白点或黑点内部 我们就需要连边使得每个点度数相同
每次选两个剩余度最大的点相连是错误的
反例 6 2
那么应该怎么连 需要Havel-Hakimi定理
由非负数组成的非增序列s:d1,d2,⋯,dn(n≥2,d1≥1)是可图的,当仅当序列s1:d2−1,d3−1,⋅⋅⋅,dd1+1−1,dd1+2,⋯,dn
是可图的。
每次选一个剩余度最大的点,将其与其余度最大的若干个点连接使其度满足要求。
#include<cstdio> #include<cstdlib> #include<algorithm> #include<functional> #include<queue> using namespace std; typedef pair<int,int> abcd; const int N=1000005; int a,b,c,d; int n,m; priority_queue<abcd> Q; abcd tmp ; int pnt; int main(){ freopen("kids.in","r",stdin); freopen("kids.out","w",stdout); scanf("%d%d%d%d",&a,&b,&c,&d); int t=__gcd(b,c),_x=b/t,_y=c/t; int n,m; for (m=b,n=c; m<=d || n<=a || (n&1)&&(a&1) || (m&1)&&(d&1);m+=_x,n+=_y); printf("%d %d\n",n,m); for (int i=1;i<=n;i++) Q.push(abcd(a,i)); while (!Q.empty()){ abcd t=Q.top(); Q.pop(); for (int i=1;i<=t.first;i++) printf("%d %d\n",t.second,Q.top().second),tmp[i]=Q.top(),Q.pop(); for (int i=1;i<=t.first;i++) if (--tmp[i].first) Q.push(tmp[i]); } for (int i=1;i<=m;i++) Q.push(abcd(d,i)); while (!Q.empty()){ abcd t=Q.top(); Q.pop(); for (int i=1;i<=t.first;i++) printf("%d %d\n",n+t.second,n+Q.top().second),tmp[i]=Q.top(),Q.pop(); for (int i=1;i<=t.first;i++) if (--tmp[i].first) Q.push(tmp[i]); } for (int i=1;i<=m;i++) Q.push(abcd(c,i)); for (int i=1;i<=n;i++){ for (int j=1;j<=b;j++){ abcd t=Q.top(); Q.pop(); printf("%d %d\n",i,t.second+n); if (--t.first) Q.push(t); } } return 0; }
相关文章推荐
- [字典树 最小树形图] Codeforces Gym 100307 NEERC 13 D. Dictionary
- [杂题] Codeforces Gym 101190 NEERC 16 K. Kids Designing Kids
- [交互 杂题] Codeforces Gym 100307 NEERC 13 I. Interactive Interception
- [仙人掌同构 Hash] Codeforces Gym 100307 NEERC 13 C. Cactus Automorphisms
- Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造
- [构造] Codeforces Gym 100553 NEERC 14 E. Epic Win!
- [构造] Codeforces Gym 101190 NEERC 16 C. Cactus Construction
- [三分套三分] Codeforces Gym 100307 NEERC 13 E. Easy Geometry
- Codeforces Gym 100187K K. Perpetuum Mobile 构造
- Codeforces Gym 100269K Kids in a Friendly Class 构造题
- Codeforces Round #378 (Div. 2) E. Sleep in Class
- [2-SAT 构造] Codeforces Gym 101173 CERC 16 L. Lost Logic
- [博弈论] Codeforces Gym 101190 NEERC 16 G. Game on Graph
- [构造] Codeforces Gym 101173 CERC 16 D & BZOJ 4790 Dancing Disks
- [杂题 交互] Codeforces Gym 101190 NEERC 16 I. Indiana Jones and the Uniform Cave
- [物理 杂题] Codeforces Gym 101190 NEERC 16 J. Jenga Boom
- Codeforces Round #389 (Div. 2)A. Santa Claus and a Place in a Class(水题)
- Codeforces Gym 100531I Instruction 构造
- Codeforces Gym 100425H H - Football Bets 构造
- [树形DP 费用流手动增广] Codeforces Gym 101190 NEERC 16 M. Mole Tunnels