题目描述:链接点此

这套题的github地址(里面包含了数据,题解,现场排名):点此

链接:https://www.nowcoder.com/acm/contest/104/D
来源:牛客网

题目描述

Do you remember Kanna-chan we met last year? She is so cute, and this year, she entered middle school, with Cirno. As we know, Cirno is bad at math, so she had trouble when studying physics.

Today, Kanna-chan's teacher is preparing for mid-term exam, one of the problem looks like follows:

Please calculate the equivalent resistance of the circuit below.

As Kanna-chan's teacher is too lazy, so he asked you for help, he will give you the answer of the problem, and your task is to generate a valid circuit satisfies that it's equivalent resistance equals to the answer.

输入描述:

Input contains one line with two integers, p and q, means the answer of the problem should be p/q, where , .

输出描述:

Output a circuit satisfy teacher's request. The first line of your input should be two integers, n and m, n is the number of nodes and m is the number of resistance you used. Where 

Then m lines follows, each line contains three integers, ,which means that there is a wi-Ohm resistance connected between ui and vi, , multiple resistances can be used between two nodes.

Then output two integers s, t, , means that the equivalent resistance between node s and node t equals to p/q.

输入例子:
22 9
输出例子:
3 4
1 2 2
2 3 1
2 3 1
2 3 4
1 3

-->

示例1

输入

22 9

输出

3 4
1 2 2
2 3 1
2 3 1
2 3 4
1 3

说明

 
 
题目大意:给你p和q,然后让你构建一个电路,是的电阻等于p/q;

/*
author:gsw
data:2018.04.30
link:https://www.nowcoder.com/acm/contest/104/B
accout:1697782237@qq.com(tonygsw)
*/
#define ll long long
#define IO ios::sync_with_stdio(false); #include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int m,n;
void dg(int x,int y,int k,int num)
{
if(y==)return;
n=max(num,n);
int a=x/y;
m++;
x=x-a*y;
if(x==){
m++;return;
}
int b=y/x;
m+=b;
int y1=y-b*x;
int x1=x;
dg(x1,y1,num,num+);
}
void print(int x,int y,int k,int num)
{
if(y==)return;
int a=x/y;
printf("%d %d %d\n",k,num,a);
x=x-a*y;
if(x==)
{
printf("%d %d %d\n",num,,);
return;
}
int b=y/x;
for(int i=;i<b;i++)
printf("%d %d %d\n",num,,);
int y1=y-b*x;
int x1=x;
print(x1,y1,num,num+);
}
int p,q; int main()
{
scanf("%d%d",&p,&q);
n=m=;
dg(p,q,,);
printf("%d %d\n",n,m);
print(p,q,,);
printf("1 2");
}
 

“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛 )--E. DoveCCL and Resistance的更多相关文章

  1. “今日头条杯”首届湖北省大学程序设计竞赛--F. Flower Road

    题目链接:点这 github链接:(包含数据和代码,题解):点这 链接:https://www.nowcoder.com/acm/contest/104/E来源:牛客网 题目描述 (受限于评测机,此题 ...

  2. A. Srdce and Triangle--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    如下图这是“今日头条杯”首届湖北省大学程序设计竞赛的第一题,作为赛后补题 题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 Let  be a regualr tr ...

  3. I. Five Day Couple--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 链接:https://www.nowcoder.com/acm/contest/104/H来源:牛客网 题目描述 ...

  4. D. Who killed Cock Robin--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 题目描述 由于系统限制,C题无法在此评测,此题为现场赛的D题 Who killed Cock Robin? I, ...

  5. H. GSS and Simple Math Problem--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 题目描述 Given n positive integers , your task is to calculat ...

  6. “东信杯”广西大学第一届程序设计竞赛(同步赛)H

    链接:https://ac.nowcoder.com/acm/contest/283/H来源:牛客网 题目描述 由于临近广西大学建校90周年校庆,西大开始了喜闻乐见的校园修缮工程! 然后问题出现了,西 ...

  7. 陕西师范大学第七届程序设计竞赛网络同步赛 I 排队排队排队【数组任一位可以移动到队头,最少移动几次增序/数组指针操作】

    链接:https://www.nowcoder.com/acm/contest/121/I来源:牛客网 题目描述 ACM竞赛队内要开运动会啦!!!! 竞赛队内的一群阳光乐观积极的队员们迅速的在操场上站 ...

  8. 西安电子科技大学第16届程序设计竞赛网络同步赛 G-小国的复仇

    sb找规律. 分解因数. #include<bits/stdc++.h> #define LL long long #define fi first #define se second # ...

  9. 陕西师范大学第七届程序设计竞赛网络同步赛 J 黑猫的小老弟【数论/法拉数列/欧拉函数】

    链接:https://www.nowcoder.com/acm/contest/121/J来源:牛客网 题目描述 大家知道,黑猫有很多的迷弟迷妹,当然也有相亲相爱的基友,这其中就有一些二五仔是黑猫的小 ...

随机推荐

  1. Linux Bash Shell快速入门 (二)

    BASH 中的变量介绍BASH 中的变量都是不能含有保留字,不能含有 "-" 等保留字符,也不能含有空格. 简单变量在 BASH 中变量定义是不需要的,没有 "int i ...

  2. ALAsset和ALAssetRepresentation详解

    ALAsset类代表相册中的每个资源文件,可以通过它获取资源文件的相关信息还能修改和新建资源文件,ALAssetRepresentation类代表相册中每个资源文件的详细信息,可以通过它获取资源的大小 ...

  3. switch 使用使用小技巧

    for (int i=0;i<100;i++) { switch (i) { case 1 ... 10: NSLog(@"case 1 ... 10: = %d",i); ...

  4. iOS 完全复制UIView

    如果要完全复制一个UIView和对象的时候可以使用对象序列化方法 // Duplicate UIView - (UIView*)duplicate:(UIView*)view { NSData * t ...

  5. windows2003 disk mirror failed redundency

    操作前請確認 mirror 磁盤已備份 windows2003 disk mirror failed redundency時,offline + online並不可以自動修復. 需要offline f ...

  6. QC增加Test、Defect字段

    QC--Tools--customization,在Project Entities中增加字段,在Project Lists中编辑Lookup List类型字段的指定值

  7. php函数的使用技巧

    函数的使用技巧 1. do{...}while(false)的用法 作用:使用do{...}while(false)结构可以简化多级判断时代码的嵌套. 例子: 现在要实现一个功能,但需要A.B.C.D ...

  8. openlayers中单击获取要素

    openlayers中单击获取要素 分类专栏: GIS 总结 OpenLayers   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接: ...

  9. 百度上有个最难数独, 用python跑它

    直接上代码 #!/usr/bin/python3 #coding=GB2312 import tkinter as tk import threading import time import ran ...

  10. Nginx网络架构实战学习笔记(二):编译PHP并与nginx整合、安装ecshop、商城url重写实战

    文章目录 编译PHP并与nginx整合 安装ecshop(这是一个多年前php的项目貌似,作为java开发的我暂时不去关心) 商城url重写实战 编译PHP并与nginx整合 安装mysql yum ...