CF1461 C. Random Events(简单期望)

16 篇文章 0 订阅

CF1461 C. Random Events

在这里插入图片描述
在这里插入图片描述

题目大意:
给定一个长为n的序列,m个询问,每次询问两个数第一个为从1开始所到右边界,第二个数为一个概率,代表着将这一段数组变为升序的可能性。问最后将整个数组变为非降序的概率。

思路:

首先要对询问进行分析,何时的操作为有效操作,若我们所修改的区间内为整个数组与非递减序不符的所有部分时才为我们所进行的有效操作范围,所以我们只需要从后往前遍历,找到最后一个与答案不同的地方,打上标记。如果我们所询问的数大于等于这个数,那我们就进行操作。

对于每次操作的概率我们只需累乘其失败概率最后用一减去即可,

#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<sstream>
#include<queue>

#define pi 3.1415926535
#define me(a,b,c) memset(a,b,sizeof c)

#define eps 0.00000001
//#define x first
//#define y second

using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
typedef pair<int, int> pii;
const int N = 1e6+10;
int a[N];
int b[N];
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, m;
		cin >> n >> m;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			b[i] = a[i];
		}
		int pos = 0;
		sort(b + 1, b + 1 + n);
		for (int i = n; i >= 1; i--) {
			if (a[i] != b[i]) {
				pos = i;
				break;
			}
		}
		double ans = 1;
		while (m--)
		{
			int r;
			double p;
			cin >> r >> p;
			if (r >= pos) {
				ans *=(1.0-p);
			}
		}
		if (!pos) {
			printf("%.8lf\n", 1.0);
			continue;
		}
		printf("%.8lf\n",1- ans);
	}
}
// 
//Buddha blesses the code with no bugs
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \\  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/*模拟STM32设备向EMQ发送数据 */ const mqtt = require('mqtt'); const host = 'iot-06z00cad6kypevk.mqtt.iothub.aliyuncs.com' const port = '1883' const clientId = `iqfzjbFKlyh.js_node_one|securemode=2,signmethod=hmacsha256,timestamp=1685192902891|` const connectUrl = `mqtt://${host}:${port}` const client = mqtt.connect(connectUrl, { clientId, clean: true, connectTimeout: 4000, username: 'js_node_one&iqfzjbFKlyh', password: 'f4cf365e0ed0a68ef9eff1ce571f959a66b1bc9a9970174cd55203e94975b4d2', reconnectPeriod: 1000, }) var stm32_esp8266_obj = {}; var studentNo = "2020070230114";//替换你的学号 const subcribe_topic = `/ota/device/inform/iqfzjbFKlyh/js_node_one`; const publish_topic = `/ota/device/upgrade/iqfzjbFKlyh/js_node_one`; client.on('connect', () => {D:/users/deskttop/iot/sy4/iot_cloudesp8266_mqtt_expresss console.log('MQTT Connected') client.subscribe([subcribe_topic], () => { console.log(`Subscribe to topic '${subcribe_topic}'`) }); setInterval(()=>{ var chushuiliang1=Math.floor(Math.random() * 20)+1; var chushuiliang2=Math.floor(Math.random() * 40)+1; var jinshuiliang=chushuiliang1+chushuiliang2+Math.floor(Math.random() * 10)+1; var zhuodu2 = Math.floor(Math.random() * 20)+1; var zhuodu3 = Math.floor(Math.random() * 20)+1; var zhuodu1 = zhuodu2+zhuodu3+Math.floor(Math.random() * 5)+1; var publish_obj={ error:0, wendu1:Math.floor(Math.random() * 40), wendu2:Math.floor(Math.random() * 40), yulv1:Math.random().toFixed(4), yulv2:Math.random().toFixed(4), yewei:Math.random().toFixed(4), ph1:Math.floor(Math.random() * 13), ph2:Math.floor(Math.random() * 13), shui:[jinshuiliang,chushuiliang1,chushuiliang2], zhuodu:[zhuodu1,zhuodu2,zhuodu3] } client.publish(publish_topic, JSON.stringify(publish_obj), { qos: 0, retain: false }, (error) => { if (error) { console.error(error) } }) },5000); }) client.on('message', (topic, payload) => { console.log('Received Message:', topic, payload.toString()); stm32_esp8266_obj = JSON.parse(payload); // console.log(stm32_esp8266_obj); })
最新发布
06-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值