The Preliminary Contest for ICPC Asia Shenyang 2019 G. Special necklace(物理求并联电阻阻值)

The Preliminary Contest for ICPC Asia Shenyang 2019  G. Special necklace(物理求并联电阻阻值)

 

The Preliminary Contest for ICPC Asia Shenyang 2019  G. Special necklace(物理求并联电阻阻值)

The Preliminary Contest for ICPC Asia Shenyang 2019  G. Special necklace(物理求并联电阻阻值)

题意:求并联电阻的阻值,水题妈蛋的!!!我用java大整数T的要命!,用String就对了 !!我服了!!

题解:很水,画个图看一下就好了,注意每条边的阻值为3a,为什吗呢,看图:

The Preliminary Contest for ICPC Asia Shenyang 2019  G. Special necklace(物理求并联电阻阻值)

好啦呀!接下来是推图啦:

n=1的时候:

The Preliminary Contest for ICPC Asia Shenyang 2019  G. Special necklace(物理求并联电阻阻值)

n=2的时候:

The Preliminary Contest for ICPC Asia Shenyang 2019  G. Special necklace(物理求并联电阻阻值)

n=3的时候:

The Preliminary Contest for ICPC Asia Shenyang 2019  G. Special necklace(物理求并联电阻阻值)

 是不是很有规律,就像那种除法模拟一样,从下往上搞就完事,因为n很大所以肯定是在并联很多之后就没影响了,果断打表,就好了,然后就会发现,大约在n=10左右就不变了(a前面那个系数),所以就很简单啦,上代码:

java:

import java.io.*;
import java.math.*;
import java.util.StringTokenizer;
class InputReader {
    BufferedReader buf;
    StringTokenizer tok;
    InputReader() {
        buf = new BufferedReader(new InputStreamReader(System.in));
    }
    boolean hasNext() {
        while (tok == null || !tok.hasMoreElements()) {
            try {
                tok = new StringTokenizer(buf.readLine());
            } catch (Exception e) {
                return false;
            }
        }
        return true;
    }
    String next() {
        if (hasNext())
            return tok.nextToken();
        return null;
    }
    int nextInt() {
        return Integer.parseInt(next());
    }
    long nextLong() {
        return Long.parseLong(next());
    }
    double nextDouble() {
        return Double.parseDouble(next());
    }
    BigInteger nextBigInteger() {
        return new BigInteger(next());
    }
    BigDecimal nextBigDecimal() {
        return new BigDecimal(next());
    }
}
public class Main{ 
	static double a[] = new double [100];
	static double fuck;
	static void init() {
		BigInteger x=BigInteger.valueOf(5l);
		BigInteger y=BigInteger.valueOf(3l);
		String s1=x.toString();
		BigDecimal ss1=new BigDecimal(s1);
		String s2=y.toString();
		BigDecimal ss2=new BigDecimal(s2);
		a[1]=ss1.divide(ss2,12,BigDecimal.ROUND_DOWN).doubleValue();
		for (int i = 2; i <= 10;i++) {
			BigInteger yy=x.multiply(BigInteger.valueOf(3l));
			BigInteger xx=y.multiply(BigInteger.valueOf(3l)).add(yy).add(x);
			BigInteger gcdd=xx.gcd(yy);
			xx=xx.divide(gcdd); yy=yy.divide(gcdd);
			yy=yy.add(xx.multiply(BigInteger.valueOf(3l)));
			gcdd=xx.gcd(yy);
			xx=xx.divide(gcdd); yy=yy.divide(gcdd);
			xx=xx.multiply(BigInteger.valueOf(3)).add(yy);
			yy=yy.multiply(BigInteger.valueOf(3l));
			gcdd=xx.gcd(yy);
			xx=xx.divide(gcdd); yy=yy.divide(gcdd);
			x=yy;
			y=xx;
			gcdd=x.gcd(y);
			s1=x.toString();
			ss1=new BigDecimal(s1);
			s2=y.toString();
			ss2=new BigDecimal(s2);
			a[i]=ss1.divide(ss2,12,BigDecimal.ROUND_DOWN).doubleValue();
		}
	}
	static InputReader cin=new InputReader();
    static PrintWriter cout=new PrintWriter(System.out);
	public static void main(String[] args) {
		init();//模拟那个过程,从下到上
		int t=cin.nextInt();
		String n;
		while(t-->0) {
			n=cin.next();//用大整数会T
			fuck=cin.nextDouble();
			if(n.length()>=2) {
				System.out.printf("%.10f\n",a[10]*fuck);
			}
			else System.out.printf("%.10f\n",a[n.charAt(0)-'0']*fuck);
		}
	}
}

C++;

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcdd(ll x,ll y){
	return y==0? x:gcdd(y,x%y);
}
double a[50];
void init(){
	ll x=5,y=3;
	ll gcd;
	a[1]=(double)x/y;
	for (int i = 2; i <= 10;i++){
		ll yy=x*3;
		ll xx=y*3+yy+x;
		gcd=gcdd(xx,yy);
		xx/=gcd;yy/=gcd;		
		yy=yy+xx*3;
		gcd=gcdd(xx,yy);
		xx/=gcd;yy/=gcd;	
		xx=xx*3+yy;
		yy*=3;
		gcd=gcdd(xx,yy);
		xx/=gcd;yy/=gcd;
		x=yy;
		y=xx;
		gcd=gcdd(x,y);
		a[i]=(double)x/y;
	}
} 
int main(){
	init();//模拟那个过程,从下到上
	int t;
	scanf("%d",&t);
	while(t--){
		string s;
		double k;
		cin >> s;
		scanf("%lf",&k);
		int len=s.size();
		if(len>=2){
			printf("%.10f\n",a[10]*k);
		}
		else printf("%.10f\n",a[s[0]-'0']*k);
	}
	return 0;
} 

 

 

上一篇:ACM-ICPC 2017 Asia Shenyang


下一篇:Spring常用工具类