[LG5323][BJOI2019]光线

博客围绕多层玻璃透光率问题展开,题目是有n层玻璃,每层有一定透过率和反射率,求一束光从左向右射过的透光率。题解指出可将连续几层玻璃合成一层,给出了前i+1层玻璃透过率和从右向左反射率的计算公式,还给出了C++代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

令$A$为前$i$层玻璃的透过率,$B$为前$i$层玻璃从右向左的反射率。$a$为第$i+1$层玻璃的透过率,$b$为第$i$层玻璃的反射率。那么前$i+1$层玻璃的透过率为$A'$,前$i+1$层玻璃从右向左的反射率为$B'$
$$
A'=Aa\sum_{i=0}^{\infty}(Bb)^i\\
\because Bb<1\\
\therefore A'=\dfrac{Aa}{1-Bb}\\
\begin{align*}
B'&=b+a^2B\sum_{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 << '\n';
	return 0;
}

  

转载于:https://www.cnblogs.com/Memory-of-winter/p/11045085.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值