2015 多校联赛 ——HDU5302(构造)

2015 多校联赛 ——HDU5299(树删边) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 593    Accepted Submission(s): 164 Problem Description There are n circles on 阅读详情

Connect the Graph

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 108    Accepted Submission(s): 36
Special Judge


Problem Description
Once there was a special graph. This graph had  n vertices and some edges. Each edge was either white or black. There was no edge connecting one vertex and the vertex itself. There was no two edges connecting the same pair of vertices. It is special because the each vertex is connected to at most two black edges and at most two white edges. 

One day, the demon broke this graph by copying all the vertices and in one copy of the graph, the demon only keeps all the black edges, and in the other copy of the graph, the demon keeps all the white edges. Now people only knows there are  w0  vertices which are connected with no white edges,  w1  vertices which are connected with  1 white edges,  w2  vertices which are connected with  2 white edges,  b0  vertices which are connected with no black edges,  b1  vertices which are connected with  1 black edges and  b2  vertices which are connected with  2 black edges.

The precious graph should be fixed to guide people, so some people started to fix it. If multiple initial states satisfy the restriction described above, print any of them.
 

Input
The first line of the input is a single integer  T (T≤700) , indicating the number of testcases. 

Each of the following  T lines contains  w0,w1,w2,b0,b1,b2 . It is guaranteed that  1≤w0,w1,w2,b0,b1,b2≤2000  and  b0+b1+b2=w0+w1+w2 . 

It is also guaranteed that the sum of all the numbers in the input file is less than  300000.
 

Output
For each testcase, if there is no available solution, print  −1 . Otherwise, print  m in the first line, indicating the total number of edges. Each of the next  m lines contains three integers  x,y,t , which means there is an edge colored  t connecting vertices  x and  y.  t=0  means this edge white, and  t=1  means this edge is black. Please be aware that this graph has no self-loop and no multiple edges. Please make sure that  1≤x,y≤b0+b1+b2 .
 

Sample Input
  
2 1 1 1 1 1 1 1 2 2 1 2 2
 

Sample Output
  
-1 6 1 5 0 4 5 0 2 4 0 1 4 1 1 3 1 2 3 1
 

Source
 

题意:构造一个图使其满足:

白边:入度为0的数目为a[0],入度为1的数目为a[1],入度为2的数目为a[2],黑边同理。


思路:

入度为1的点必定为偶数,否则输出-1

点的总数:a[0] + a[1] + a[2]

 边的总数 = 入度总数 /2  = (a[1]+b[1])/2 + a[2] + b[2]

入度为二的:(1,2)(2,3)(3,4).... 所以 a[2] >= 0

入度为一的: (1,2)(3,4).....    而且构造入度为二的链会有2个入度1,所以吧a[1] > 2

黑色边的处理需要间隔2的跳变(图中两点之间只有一条边) 

//学习的别人的代码,把感觉能做题的都写一遍吧,当然那种代码长而且没法理解了,咳咳。。。  以后再说


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
int MAX=0x3f3f3f3f;
using namespace std;
const int INF = 0x7f7f7f;
const int MAXM = 12e4+5;

int p[1000005];
int a[3],b[3];

int main()
{

    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d %d %d %d %d %d",&a[0],&a[1],&a[2],&b[0],&b[1],&b[2]);
        int sum = 0;
        for(int i = 0; i < 3; i++)
            sum+=a[i];

        if((a[1] & 1) || (b[1] & 1))
        {
            printf("-1\n");
            continue;
        }

        int n = (a[1]/2 + a[2]+b[1]/2 + b[2]);

         if(sum==4)
        {
            printf("4\n1 2 0\n1 3 0\n2 3 1\n3 4 1\n");
            continue;
        }

        printf("%d\n",n);
        int t = 1;
        while(a[2] >=0)
        {
            printf("%d %d 0\n",t,t+1);
            t++;
            a[2]--;
        }
        t++;
        while(a[1] > 2)
        {
            printf("%d %d 0\n",t,t+1);
            t+=2;
            a[1]-=2;
        }
        int tmp = 0;
        for(int i = 1;i <= sum ;i+=2) p[tmp++] = i;
        for(int i = 2;i <= sum;i+=2)   p[tmp++] = i;

        tmp = 0;
        while(b[2] >= 0)
        {
            printf("%d %d 1\n",min(p[tmp],p[tmp+1]),max(p[tmp],p[tmp+1]));
            tmp++;
            b[2]--;
        }
        tmp ++;
        while(b[1] > 2)
        {
            printf("%d %d 1\n",min(p[tmp],p[tmp+1]),max(p[tmp],p[tmp+1]));
            tmp+=2;
            b[1]-=2;
        }

    }
    return 0;
}






对单周期 RISC-V 处理器进行扩展 阅读详情

相关推荐

Tushare Pro的安装使用——“抱歉,您没有访问该接口的权限,权限的具体详情访问:https://tushare.pro/document/1?doc_id=108”问题

最近做毕设关于量化交易的, 因此一直使用tushare作数据源,但是过程中到一些问题,因此这里写篇文章,供大家一起交流下。 Tushare简介 Tushare是一个免费、开源的python财经数据接口包。拥有如股票、基金、期货等行情数据,公司财务、基金经理等基本面数据,以及债券、外汇、行业、大数据、区块链。Tushare返回的绝大部分的数据格式都是pandas DataFrame类型,因此非常方便...

sinat_40875078的博客 1万+

HDOJ 5302 Connect the Graph 构造

如果1度的点不是偶数,则无解 构造一个环,这样所有的点都可以有俩个度.其他所有情况都可以通过删掉一些边来得到,而且黑边和白边是互相独立的....考虑到不能有重边,则至少得有2*n条边,所以n==4的情况(1 2 1)需要特判 Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/

码代码的猿猿 868

microblaze之Video Processing Subsystem调试误区

内容:总结video processing subsystem调试中遇到的问题,以及在解决问题中的思路方法论,引为前车之鉴。 1,我的目的是希望采用vps中的scaler模块对图像进行拉伸缩小。IP的配置如下: 2,整个系统的框架图如下,仅比上期的内容增加了scaler模块,如下: 3,查手册,可以知道这个scaler only组件分成了hscale,vscale和GPIO,其中GPIO是控制上下游stream流控设备复位用,暂时忽略。 hscale和vscale的寄存器空间如下,主要关注图

YDY5659150的专栏 3555

HDU 5302(Connect the Graph- 构造)

Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 456    Accepted Submission(s): 144 Special Judge Problem Description O

nike0good |Oier&ACMer | 熟能生巧 2658

python -- 海洋气象科研论文中常用绘图配色汇总

当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照下面的知识点去找对应的学习资源,保证自己学得较为全面。观看全面零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。可以通过自定义选取不同颜色的rgb,通过自定义的方式构建colormap。

weixin_68789096的博客 972

告别MATLAB!用Python的PYPOWER搞定电力系统潮流计算(附Case30完整代码)

本文介绍了如何从MATLAB迁移到Python,使用PYPOWER工具包进行电力系统潮流计算。通过详细的环境准备、数据接口兼容性实践、潮流计算实现及最优潮流计算进阶,帮助工程师和学生无缝过渡到Python生态。文章还展示了结果处理与可视化技巧,并附有Case30完整代码示例。

weixin_30411819的博客 298

2015 多校联赛 ——HDU5302(矩阵快速幂)

The Goddess Of The Moon Sample Input 2 10 50 12 1213 1212 1313231 12312413 12312 4123 1231 3 131 5 50 121 123 213 132 321 Sample Output 86814837 797922656 ...

diaocuiguo2493的博客 159

手把手教你理解ARM SoC中的PPU:电源管理IP的配置与实战避坑指南

本文深入解析ARM SoC中的PPU(Power Policy Unit)电源管理IP,提供详细的配置指南与实战避坑技巧。从PPU基础架构、寄存器配置到与PCSM的协同工作,全面介绍如何优化电源管理策略,解决常见配置误区,并分享高级调试与性能优化方法,助力工程师提升低功耗SoC设计效率。

weixin_28693447的博客 479

hdu 5302 Connect the Graph(构造)

题目链接:hdu 5302 Connect the Graph 当w1或者是b1为奇数时,无解。其他情况下一定可以构造出一条链和多个节点对,只要保证两点之间没有重边就行了。一种间隔1为一对,另一种间隔2为一对。 #include #include #include using namespace std; int N; int jump(int p, int k)

不慌不忙、不急不躁 743

MSPM0G3507+逐飞库:5分钟搞定KEIL环境配置与LED闪烁(附常见错误解决)

本文详细介绍了如何使用MSPM0G3507微控制器和逐飞库快速配置KEIL开发环境,并实现LED闪烁功能。从芯片支持包安装、逐飞库工程配置到烧录调试,提供了完整的步骤和常见错误解决方案,帮助开发者5分钟内完成环境搭建。

lambda的博客 1193

HFSS仿真平行线定向耦合器学习笔记

材料:FR4(玻璃纤维环氧树脂),介电常数:4.4,损耗角正切:0.02,厚度0.8mm。扫频方式:快速扫频,扫频范围:1.0GHz~3.0GHz,步进:0.01GHz。端口2是端口1关于Y轴对称,端口3,端口4是端口1和端口2关于X轴对称得到。求解中心频率:2.0GHz,迭代次数:20,收敛误差为0.02。右键设置边界条件----辐射边界。激励方式:集总端口激励。

qq_36521926的博客 4485

hdu 5533(几何水)

Input The first line contains a integer T indicating the total number of test cases. Each test case begins with an integer n, denoting the number of stars in the sky. Following n lines, each

阳光下的泡沫 2190

用MATLAB计算卡方值

然后,我们计算了期望频数,即在两个分类变量独立的情况下,每个单元格的预期频数。接下来,我们使用卡方检验的公式计算了卡方值。卡方检验是一种常用的统计方法,用于确定两个分类变量之间是否存在相关性。它基于观察到的频数和期望频数之间的差异来评估分类变量之间的独立性。在MATLAB中,我们可以使用。请注意,这只是一个简单的示例代码,用于说明如何使用MATLAB计算卡方值。在实际应用中,您可能需要根据您的具体数据和研究问题进行相应的修改和调整。在上面的代码中,我们首先创建了两个分类变量。函数显示了计算得到的卡方值。

CodeNexus的博客 2658

hdu 5534(dp)

Input The first line contains an integer T indicating the total number of test cases. Each test case starts with an integer n in one line, then one line with n−1 integers f(1),f(2),…,f(n−1).

阳光下的泡沫 1399

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

hdu 5532(最长上升子序列)

Input The first line contains an integer T indicating the total number of test cases. Each test case starts with an integer n in one line, then one line with n integers a1,a2,…,an. 1≤T≤2000

阳光下的泡沫 1343

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

*hdu 5536(字典树的运用)

Input The first line of input contains an integer T indicating the total number of test cases. The first line of each test case is an integer n, indicating the number of chips produced today

阳光下的泡沫 1190

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

hdu 5538(水)

Input The first line contains an integer T indicating the total number of test cases. First line of each test case is a line with two integers n,m. The n lines that follow describe the array

阳光下的泡沫 1088

hdu 5489(LIS最长上升子序列)

题意:一个含有n个元素的数组,删去k个连续数后,最长上升子序列        /*思路参考GoZy 思路: 4 2 3 [5 7 8] 9 11 ,括号表示要删掉的数, 所以  最长上升子序列  =   ] 右边数A的lis + [左边最大值小于A的lis  即相当于枚举删除的所有情况,并求它们的LIS,取最大值 如本例 : 最长 = 2[ 9 11]  + 2[2 3],  然后将框从左

阳光下的泡沫 1030

hdu 5446(中国剩余+lucas+按位乘)

题意:c( n, m)%M    M = P1 * P2 * ......* Pk Lucas定理是用来求 c(n,m) mod p,p为素数的值。得出一个存余数数组,在结合中国剩余定理求值 其中有个地方乘积可能超范围,所以按位乘(数论方面薄弱啊,学习学习)。 #include #include #include #include #include using namesp

阳光下的泡沫 941

2015 多校联赛 ——HDU5334(构造)

Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 237    Accepted Submission(s): 56 Special Judge Problem Descripti

阳光下的泡沫 844

hihocoder1258(水)(2015ACM/ICPC北京站)

题意: 给你B,C,S三种模式,当出现S时直接得分最多300(即perfect) 当是B,C时后面会跟一个数字,当后面的数字是从1开始的连续时,直接得分最多300(即perfect) 问给你一系列,最多能得到多少个pefect 思路: 当出现S时直接+,当出现B或者C时,判断它们后面是否有1,有则+ 做的时间想复杂了- - #include #include #i

阳光下的泡沫 810

hdu 5130(2014广州 圆与多边形相交模板)

题意:一个很多个点p构成的多边形,pb 设p(x,y),       (x - xb)^2+(y - yb)^2 / (x - xa)^2+(y - ya)^2  = k^2 所以可以化成圆的一般式x^2 + y^2 + dx + ey + f = 0; 推公式: 圆心:(-d/2,-e/2)       半径:(sqrt(d*d + e*e - 4*f)) / 2 得出圆后,套模板求

阳光下的泡沫 768

hdu 5583 Kingdom of Black and White

Kingdom of Black and White Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 585    Accepted Submission(s): 193 Problem Description I

阳光下的泡沫 742
上一篇: BestCoder 1st Anniversary ——HDU5312(数学推导)
下一篇: 2015 多校联赛 ——HDU5302(矩阵快速幂)
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值