Kids in a Friendly Class

题目连接:

http://codeforces.com/gym/100269/attachments

Description

Kevin resembles his class in primary school. There were girls and boys in his class. Some of them were

friends, some were not. But if one person considered another person a friend, the opposite was also true.

Interestingly, every girl had exactly a friends among girls and exactly b friends among boys, whereas

every boy had exactly c friends among girls and exactly d friends among boys.

Kevin does not remember the size of his class. Help him reconstruct the class with minimal possible

number of kids, such that the above conditions are satisfied.

Input

The only line contains four integers a, b, c, and d (1 ≤ a, b, c, d ≤ 50)

Output

Output an example of a class of minimal possible size satisfying the above conditions.

The first line should contains two positive integers: m — the number of girls, and n — the number of

boys.

Let’s assign numbers 1 through m to the girls and m + 1 through m + n to the boys.

Each of the next lines should contain a pair of distinct integers describing a pair of friends by their

numbers. Each pair of friends should appear exactly once in this list.

Sample Input

1 2 1 2

Sample Output

2 4

1 2

1 3

1 5

2 4

2 6

3 4

3 5

4 6

5 6

Hint

题意

每个女生认识a个女生,b个男生

每个男生认识c个女生,d个男生

问你怎么构图,才能使得男生+女生最少

题解:

首先我们假设知道了男生和女生的数量的话

建边就很简单,贪心去建边就好了,每次连接度数最小的点

至于怎么知道男生和女生的数量呢?

首先男生和女生的数量肯定是lcm(b,c)的倍数

然后不断check就好了

check主要只判断同性之间就好了

每条边必须连接两个点之内的check一下就好了

有个定理叫做Havel-Hakimi定理

代码

#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
if(b==0)return a;
return gcd(b,a%b);
}
int a,b,c,d;
bool check(int n,int m)
{
if(b>m)return false;
if(c>n)return false;
if(a>=n)return false;
if(d>=m)return false;
if(n%a!=0)return false;
if(m%b!=0)return false;
return true;
}
void getedge(int n,int m)
{
priority_queue<pair<int,int> >Q;
for(int i=1;i<=n;i++)
Q.push(make_pair(a,i));
while(!Q.empty())
{
pair<int,int> now = Q.top();
Q.pop();
for(int i=0;i<now.first;i++)
{
pair<int,int> next = Q.top();
Q.pop();
printf("%d %d\n",now.second,next.second);
next.first--;
Q.push(next);
}
} for(int i=n+1;i<=n+m;i++)
Q.push(make_pair(d,i));
while(!Q.empty())
{
pair<int,int> now = Q.top();
Q.pop();
for(int i=0;i<now.first;i++)
{
pair<int,int> next = Q.top();
Q.pop();
printf("%d %d\n",now.second,next.second);
next.first--;
Q.push(next);
}
} priority_queue<pair<int,int> >Q1;
priority_queue<pair<int,int> >Q2;
for(int i=1;i<=n;i++)
Q1.push(make_pair(b,i));
for(int i=n+1;i<=m+n;i++)
Q2.push(make_pair(c,i));
while(!Q1.empty())
{
pair<int,int> now = Q1.top();
Q1.pop();
for(int i=0;i<now.first;i++)
{
pair<int,int> next = Q2.top();
Q2.pop();
printf("%d %d\n",now.second,next.second);
next.first--;
if(next.first!=0)Q2.push(next);
}
}
}
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);
int x=b/t,y=c/t;
int n,m;
for(n=b,m=c;n<=d||m<=a||(m&1)&&(a&1)||(n&1)&&(d&1);n+=x,m+=y);
swap(n,m);
cout<<n<<" "<<m<<endl;
getedge(n,m);
}

Codeforces Gym 100269K Kids in a Friendly Class 构造题的更多相关文章

  1. Codeforces Gym 102392F Game on a Tree (SEERC2019 F题) 题解

    题目链接:https://codeforces.com/gym/102392/problem/F 题意:被这题题意坑了很久,大意是说有一棵根为 \(1\) 的树,每个节点初始都是白色, \(Alice ...

  2. Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造

    Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...

  3. Codeforces Gym 100650C The Game of Efil 模拟+阅读题

    原题链接:http://codeforces.com/gym/100650/attachments/download/3269/20052006-acmicpc-east-central-north- ...

  4. Codeforces Gym 101194G Pandaria (2016 ACM-ICPC EC-Final G题, 并查集 + 线段树合并)

    题目链接  2016 ACM-ICPC EC-Final Problem G 题意  给定一个无向图.每个点有一种颜色. 现在给定$q$个询问,每次询问$x$和$w$,求所有能通过边权值不超过$w$的 ...

  5. codeforces 1438D,思路非常非常巧妙的构造题

    大家好,欢迎来到codeforces专题. 今天选择的问题是contest1438的D题,全场通过人数为1325人.一般在codeforces当中千人通过的题难度都不算太高,但是这题有点例外,虽然没有 ...

  6. Codeforces Gym 100269A Arrangement of Contest 水题

    Problem A. Arrangement of Contest 题目连接: http://codeforces.com/gym/100269/attachments Description Lit ...

  7. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  8. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  9. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

随机推荐

  1. python自动开发之第二十五天

    一.组合搜索 参考: http://www.cnblogs.com/ccorz/p/5985205.html 二.JSONP 1.在同源策略下,在某个服务器下的页面是无法获取到该服务器以外的数据的,但 ...

  2. Yii 1.1.17 一、安装、目录结构、视图、控制器、扩展自定义函数

    这几天了解了一下Yii框架,以简单的博客项目实战入门.大致的实现流程做个记录. 一.Yii 安装与环境检测 从 www.yiiframework.com 获取一份Yii的拷贝,解压到 /wwwroot ...

  3. 004 ConcurrentHashMap原理

    下面这部分内容转载自: http://www.haogongju.net/art/2350374 JDK5中添加了新的concurrent包,相对同步容器而言,并发容器通过一些机制改进了并发性能.因为 ...

  4. swift中的如果在构造方法中使用KVC, 调用了super.init(), 报错, 基本数据类型属性找不到

    swift要求, 属性必须有初始化值, 如果不对其赋值, 可以加一个?系统会默认给其包装一个可选值(直说就是nil) 如果定义一个基本类型, 建议直接赋值, 不建议使用? 下面说下标题中的问题 有时候 ...

  5. Jmeter性能测试示例

    这次成功做了一个jmeter借口性能测试的简单测试示例,分享一下给大家. jmeter作为一个简单的开源工具,基于java的性能测试工具,使用起来很简单. 也可以作为二次开发,复杂的情形可以自己写代码 ...

  6. linux命令(33):tail命令

    1.命令格式; tail[必要参数][选择参数][文件] 2.命令功能: 用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理.常用查看日志文件. 3.命令参数: -f 循环读取 -q 不显示 ...

  7. redis之(九)redis的事务机制

    [一]什么是redis的事务 --->redis的事务是一组命令的集合. --->redis的事务是保证一组命令,要么都执行,要么都不执行.但不支持一组命令中,其中一个或多个执行失败,不支 ...

  8. Pycharm中的Django项目连接mysql数据库

    一.安装Pycharm和Django就不详细说了,自行百度 二.新建Django项目也不说了 三.配置Django连接到mysql 1.models.py写一个类,继承models.Model cla ...

  9. mac安装jdk1.8

    一. http://www.oracle.com/technetwork/java/javase/downloads/index.html 去jdk官网下载 二.安装 一路傻瓜式安装,下一步下一步 三 ...

  10. win 10 下面安装 mysql-8.0.12-winx64 的过程

    win 10 下面安装 mysql-8.0.12-winx64 的过程 1.官网下载 mysql 2.解压到你要安装的目录 3.在mysql目录D:\Programming\mysql-8.0.12- ...