题目描述:链接点此

这套题的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系统之-常用命令及技巧

    一. 通用命令:1.date :print or set the system date and time2. stty -a: 可以查看或者打印控制字符(Ctrl-C, Ctrl-D, Ctrl-Z ...

  2. shell(计算机壳层)(一)

    在计算机科学中,Shell俗称壳(用来区别于核),是指“提供使用者使用界面”的软件(命令解析器).它类似于DOS下的command和后来的cmd.exe.它接收用户命令,然后调用相应的应用程序. wi ...

  3. ecshop整合discuz教程完美教程

    所需软件: ecshop安装包:    ECShop_V2.7.3_UTF8_release1106.rarucenter安装包:   UCenter_1.6.0_SC_UTF8.zipdiscuz! ...

  4. [CSP-S模拟测试58]题解

    以后题解还是单独放吧. A.Divisors 根号筛求所有数的因子,扫一遍去重统计即可. #include<cstdio> #include<iostream> #includ ...

  5. (54) C# 调用 kernel32.dll

    https://www.cnblogs.com/cwy173/archive/2010/10/02/1841321.html Kernel32 API AddAtom 向本地原子表添加一个字符串 Al ...

  6. 对业务类进行构造的工厂类BLLFactory

    using System; using System.Collections.Generic; using System.Text; using System.Collections; using W ...

  7. less&sass

    定义: less是一种动态样式语言,对css赋予了动态语言的特性,比如变量.继承.运算.函数,既可以运行在客户端,也可以运行在服务器端,依赖JavaScript   sass是一种动态语言,属于缩排语 ...

  8. HTTP权威指南读书笔记——第一章(HTTP概述)

    1.HTTP(Hypertext Transfer Protocol,超文本传输协议)是在万维网上进行通信时所使用的协议方案,HTTP是应用层协议,无需关心网络通信的细节,细节交给了传输层协议TCP/ ...

  9. CodeForces - 337D 树形dp

    题意:一颗树上有且仅有一只恶魔,恶魔会污染距离它小于等于d的点,现在已经知道被污染的m个点,问恶魔在的可能结点的数量. 容易想到,要是一个点到(距离最远的两个点)的距离都小于等于d,那么这个点就有可能 ...

  10. 【datatable】正在加载中的信息提示

    datatable插件 DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, ...