Codeforces Round #689 (Div. 2) C. Random Events(思维)

链接 C. Random Events

题意

给出一个长度为 n n n 的序列,给出 q q q 个操作 ( r , p ) (r,p) rp,表示从 [ 1 , r ] [1,r] [1,r] 升序排列的概率是 p p p ,问最后序列升序排列的概率;

思路

首先从后往前遍历,确定 a [ i ] ! = i a[i] != i a[i]!=i 的第一个位置 i d id id,对于 i d id id 左边的排序对答案没有贡献,而对 i d id id 右边排序,只要成功一次就可以,所以我们只需要算出排序不成功的总概率 a n s ans ans,答案就是 1 − a n s 1-ans 1ans

AC代码

#include <bits/stdc++.h>
#define mes memset
#define mec memcpy
#define x first
#define y second
#define pb push_back
#define be(x) (x).begin(), (x).end()
#define cl(x) memset((x), 0, sizeof (x))
#define sz(x) (int)(x).size()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll,ll> PLL;

const double pi = acos(-1);
const double eps = 1e-8;
const int N = 100010;
const int null = 0x3f3f3f3f,INF = 1e9;
const ll mod = 998244353;

int T;
int a[N];

int main()
{
	cin >> T;
	while (T --)
	{
		int n, k;
		cin >> n >> k;
		for (int i = 1; i <= n; i ++) cin >> a[i];

		int id = -1;
		for (int i = n; i >= 1; i --)
		{
			if (a[i] != i)
			{
				id = i;
				break;
			}
		}

		double ans = 1;
		while (k --)
		{
			int x;
			double res;
			cin >> x >> res;
			if (x >= id) ans *= (1 - res);
		}

		if (id == -1) printf("1.00000000\n");
		else printf("%.8lf\n", 1 - ans);
	}

	return 0;
}

——END

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

半碗无糖蓝莓冻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值