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

题目描述:链接点此

这套题的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.

示例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:[email protected](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==0)return;
    n=max(num,n);
    int a=x/y;
    m++;
    x=x-a*y;
    if(x==0){
        m++;return;
    }
    int b=y/x;
    m+=b;
    int y1=y-b*x;
    int x1=x;
    dg(x1,y1,num,num+1);
}
void print(int x,int y,int k,int num)
{
    if(y==0)return;
    int a=x/y;
    printf("%d %d %d\n",k,num,a);
    x=x-a*y;
    if(x==0)
    {
        printf("%d %d %d\n",num,2,0);
        return;
    }
    int b=y/x;
    for(int i=0;i<b;i++)
        printf("%d %d %d\n",num,2,1);
    int y1=y-b*x;
    int x1=x;
    print(x1,y1,num,num+1);
}
int p,q;

int main()
{
    scanf("%d%d",&p,&q);
    n=m=0;
    dg(p,q,1,3);
    printf("%d %d\n",n,m);
    print(p,q,1,3);
    printf("1 2");
}
 

猜你喜欢

转载自www.cnblogs.com/fantastic123/p/8973754.html