某游戏中,某套装备共计3件(ABC),通关某副本必会掉落该套装中的随机一套装备,其中装备A的掉落概率为50%,装备B的掉落概率为40%,装备C的掉落概率为10%,集齐全部3件装备所需通关副本次数的期望是多少
时间: 2023-05-27 08:01:41 浏览: 88
Null is a term used to represent the absence of any value or data in a computer program. It is often used as a placeholder value, indicating that a variable or field has not been assigned any value or has no meaningful value to represent at a particular point in the program. In databases, null is used to indicate the absence of data in a particular field or record. Programmers must be careful to handle null values properly to prevent errors and ensure that their programs run correctly.
相关问题
excel某一个字符串中含有指定字符,返回一个数值
要实现在Excel中查找某一个字符串中是否含有指定字符并返回一个数值,可以使用公式函数来完成。
首先,可以使用FIND函数来查找指定字符在字符串中的位置。FIND函数的语法为=FIND(要查找的字符, 在哪个单元格中查找, 从哪个位置开始查找)。例如,要在A1单元格中查找是否含有字符"abc",可以使用=FIND("abc", A1, 1)。
接下来,如果FIND函数能够找到指定字符,就会返回字符在字符串中的位置,如果找不到则会返回错误值#VALUE。可以使用IFERROR函数来判断FIND函数的返回值,如果找到则返回一个自定义的数值,如果找不到则返回另一个自定义的数值。IFERROR函数的语法为=IFERROR(要判断的值, 如果错误则返回什么)。例如,要判断FIND函数的返回值,可以使用=IFERROR(FIND("abc", A1, 1), "找不到")。
通过以上步骤,就可以在Excel中实现查找某一个字符串中是否含有指定字符并返回一个数值。当然也可以根据实际情况自定义返回的数值。希望以上回答能够帮到你。
vue中如何实现在某一区域中多个元素随机定位显示且不重叠给出示例并判断不能重叠
在Vue中可以通过CSS样式和JavaScript代码实现多个元素随机定位且不重叠的效果。以下是一个示例:
1. HTML结构
```html
<template>
<div class="container">
<div v-for="(item, index) in items" :key="index" class="box">{{ item }}</div>
</div>
</template>
```
2. CSS样式
```css
.container {
position: relative;
width: 500px;
height: 500px;
background-color: #eee;
}
.box {
position: absolute;
width: 50px;
height: 50px;
background-color: #1abc9c;
color: #fff;
text-align: center;
line-height: 50px;
font-size: 16px;
}
```
3. JavaScript代码
```javascript
export default {
data() {
return {
items: ["A", "B", "C", "D", "E"],
positions: [],
};
},
mounted() {
this.randomPositions();
},
methods: {
randomPositions() {
const boxes = this.$el.querySelectorAll(".box");
const container = this.$el.querySelector(".container");
const containerRect = container.getBoundingClientRect();
const boxSize = boxes[0].getBoundingClientRect();
const boxWidth = boxSize.width;
const boxHeight = boxSize.height;
const maxLeft = containerRect.width - boxWidth;
const maxTop = containerRect.height - boxHeight;
for (let i = 0; i < boxes.length; i++) {
let left = this.randomNumber(0, maxLeft);
let top = this.randomNumber(0, maxTop);
let position = { left, top };
let isOverlap = this.checkOverlap(position, i);
while (isOverlap) {
left = this.randomNumber(0, maxLeft);
top = this.randomNumber(0, maxTop);
position = { left, top };
isOverlap = this.checkOverlap(position, i);
}
boxes[i].style.left = `${left}px`;
boxes[i].style.top = `${top}px`;
this.positions.push(position);
}
},
randomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
},
checkOverlap(position, currentIndex) {
for (let i = 0; i < currentIndex; i++) {
const prevPosition = this.positions[i];
const x1 = prevPosition.left;
const y1 = prevPosition.top;
const x2 = x1 + 50;
const y2 = y1 + 50;
const x3 = position.left;
const y3 = position.top;
const x4 = x3 + 50;
const y4 = y3 + 50;
if (!(x2 < x3 || x1 > x4 || y2 < y3 || y1 > y4)) {
return true;
}
}
return false;
},
},
};
```
在mounted生命周期钩子函数中,调用randomPositions方法,该方法会随机生成多个元素的位置,并通过checkOverlap方法来判断位置是否重叠。如果重叠,则重新生成位置,直到不重叠为止。最后将位置应用到元素上。
checkOverlap方法采用了矩形相交的方法来判断位置是否重叠。如果两个矩形不相交,则不重叠。
注意事项:
1. 生成的元素数量不宜过多,否则随机生成位置的时间会变长。
2. 容器的宽高需要固定,否则无法计算元素的位置。
3. 元素的宽高需要固定,否则无法计算元素的位置。
4. 不同的容器和元素宽高需要针对性地修改代码中的计算。