zoukankan      html  css  js  c++  java
  • [洛谷P5323][BJOI2019]光线

    题目大意:有$n$层玻璃,每层玻璃会让$a\%$的光通过,并把$b\%$的光反射。有一束光从左向右射过,问多少的光可以透过这$n$层玻璃

    题解:事实上会发现,可以把连续的几层玻璃合成一层玻璃,但是要注意玻璃两侧的反射率可能是不一样的。

    令$A$为前$i$层玻璃的透过率,$B$为前$i$层玻璃从右向左的反射率。$a$为第$i+1$层玻璃的透过率,$b$为第$i$层玻璃的反射率。那么前$i+1$层玻璃的透过率为$A'$,前$i+1$层玻璃从右向左的反射率为$B'$
    $$
    A'=Aasum_{i=0}^{infty}(Bb)^i\
    ecause Bb<1\
    herefore A'=dfrac{Aa}{1-Bb}\
    egin{align*}
    B'&=b+a^2Bsum_{i=0}^{infty}(Bb)^2\
    &=b+dfrac{a^2B}{1-Bb}
    end{align*}
    $$
    卡点:

    C++ Code:

    #include <iostream>
    #include <algorithm>
    #define mul(a, b) (static_cast<long long> (a) * (b) % mod)
    
    const int mod = 1e9 + 7;
    
    namespace Math {
    	inline int pw(int base, int p) {
    		static int res;
    		for (res = 1; p; p >>= 1, base = mul(base, base)) if (p & 1) res = mul(res, base);
    		return res;
    	}
    	inline int inv(int x) { return pw(x, mod - 2); }
    }
    
    int n, A, B, inv_100;
    int main() {
    	std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
    	std::cin >> n >> A >> B;
    	inv_100 = Math::inv(100);
    	A = mul(A, inv_100), B = mul(B, inv_100);
    	while (--n) {
    		static int a, b, t;
    		std::cin >> a >> b;
    		a = mul(a, inv_100), b = mul(b, inv_100);
    		t = Math::inv(mod + 1 - mul(B, b));
    		A = mul(A, a) * t % mod;
    		B = b + mul(a, a) * B % mod * t % mod;
    	}
    	std::cout << A << '
    ';
    	return 0;
    }
    

      

  • 相关阅读:
    CDH简易离线部署文档
    算法图解读书笔记
    html 知识整理
    Django admin 组件 原理分析与扩展使用 之 sites.py (一)
    阿里云 centos7 django + uWSGI+Nginx + python3 部署攻略
    git 命令和使用场景总结
    由select引发的思考
    Python 实现单例模式的一些思考
    pep 8 规范的一些记录
    python 垃圾回收机制的思考
  • 原文地址:https://www.cnblogs.com/Memory-of-winter/p/11045085.html
Copyright © 2011-2022 走看看