SkipStones

/*Problem Statement

When a stone is thrown across water, sometimes it will land on the water and bounce rather than falling in right away.

Suppose that a stone is thrown a distance of n. On each successive bounce it will travel half the distance as the previous bounce (rounded down to the nearest integer).

When it can not travel any further, it falls into the water.

If, at any point, the stone lands on an obstruction rather than water, it will not bounce, but will simply deflect and fall into the water.

Please look at the figure for further clarification (with black, red and green cells representing banks, obstructions and free water respectively).

So, if the stone is thrown a distance 7, it will bounce and travel a distance of 3, then finally a distance of 1,

having travelled a total distance of 11 (the green path in the figure).

If a stone is thrown a distance of 8, it will reach the opposite bank, and if thrown at distances of 2 or 6 it will hit an obstruction during its travel.

These are the three red paths in the figure.

You are given a String water. An ‘X’ represents an obstruction, while a ‘.’represents water free from obstruction.

You are to return an int representing the maximum distance a stone can travel and finally fall in the water, without hitting any obstructions,

and without reaching the opposite bank (going beyond the end of the string). You may choose any initial distance for the throw,

which starts from the left side of the string. A distance of 1 is the first character of the string, etc. If no initial throw will result in the stone

landing in the water without hitting an obstruction, return 0.


Definition:

Class: SkipStones
Method: maxDistance
Parameters: String
Returns: int
Method signature: int maxDistance(String water)*/

package skipStones;

public class SkipStones {

public static int maxDistance(String water) {
int dis = initDistance(water.length());

int[] distances = new int[dis];
for(int i = 0; i < dis; i++) {
distances[i] = i + 1;
}

int result = removeStone(distances, water);

int temp = result;
while((temp = temp/2) != 0) {
result = result + temp;
}

return result;
}

private static int initDistance(int length) {

int[] possibleTree = new int[length];
int path = length - 1;

for(int i=0; i < length; i++) {
if(i == 0) {
possibleTree[i] = path;
} else {
possibleTree[i] = possibleTree[i/2] - i - 1;
if(possibleTree[i] == 0) return i + 1;
else if(possibleTree[i] < 0) return i;

if (i + 1 < length) {
possibleTree[i + 1] = possibleTree[i / 2] - i - 2;
if (possibleTree[i + 1] == 0) return i + 2;
else if (possibleTree[i + 1] < 0) return i + 1;

i++;
}
}
}
return 0;
}

private static int removeStone(int[] distances, String water) {
char[] stones = water.toCharArray();

for (int i = 0; i < stones.length; i++) {
if (stones[i] == 'X') {
if (i < distances.length) {
distances[i] = 0;
}
possibleDistance(distances, i + 1);
}
}

for(int k = distances.length - 1; k >= 0; k--) {
if(distances[k] != 0) return distances[k];
}

return 0;
}

private static void possibleDistance(int[] distances, int length) {

int counter = 0;

for(int i=0; i < distances.length; i++) {
int temp = distances[i];
if(temp == length) {
distances[i] = 0;
} else {
int value = distances[i];
while((temp = temp/2) != 0) {
value = value + temp;
if(value == length) {
distances[i] = 0;
break;
}
}
}
}
}
}

内容概要:本文围绕VMware虚拟化环境在毕业设计中的应用,重点探讨其在网络安全与AI模型训练两大领域的实践价值。通过搭建高度隔离、可复现的虚拟化环境,解决传统物理机实验中存在的环境配置复杂、攻击场景难还原、GPU资源难以高效利用等问题。文章详细介绍了嵌套虚拟化、GPU直通(passthrough)、虚拟防火墙等核心技术,并结合具体场景提供实战操作流程与代码示例,包括SQL注入攻防实验中基于vSwitch端口镜像的流量捕获,以及PyTorch分布式训练中通过GPU直通实现接近物理机性能的模型训练效果。同时展望了智能化实验编排、边缘虚拟化和绿色计算等未来发展方向。; 适合人群:计算机相关专业本科高年级学生或研究生,具备一定虚拟化基础、网络安全或人工智能背景,正在进行或计划开展相关方向毕业设计的研究者;; 使用场景及目标:①构建可控的网络安全实验环境,实现攻击流量精准捕获与WAF防护验证;②在虚拟机中高效开展AI模型训练,充分利用GPU资源并评估性能损耗;③掌握VMware ESXi命令行与vSphere平台协同配置的关键技能; 阅读建议:建议读者结合VMware实验平台动手实践文中提供的esxcli命令与网络拓扑配置,重点关注GPU直通的硬件前提条件与端口镜像的混杂模式设置,同时可延伸探索自动化脚本编写与能效优化策略。
目录: 1、【coze自动化]基础和建立一个简单的机器人实操(2024).mp4 2、【coze自动化]实操案例用插件和工作流-提取文案1(做好.mp4 3、【coze自动化]实操案例用大模型+插件+工作流-提取文案2.mp4 4、【coze自动化]实操案例用2个大模型+插件+工作流-提取文案3.mp4 5、【coze自动化]实操案例完结-2大模型+4插件+工作流-提取文案4.mp4 6、【扣子coze插件篇,-探索和测试插件的系统方法1].mp4 7、【扣子Coze自动化]案例实操-文本转脑图1.mp4 8、【扣子Coze自动化]如何写工作流的代码?普通人就能搞定--简单实用.mp4 9、【扣子Coze自动化]实操案例--选择器的落地应用-判断链接还是文本,mp4 10、【扣子Coze自动化]选择器分支和代码联合高级应用-让工作流更灵活应对多种场景.mp4 11、【扣子Coze自动化]如何把机器人发布平台.mp4 12_【AI案例篇]coze工作流处理1万字长文本和详细操作思路和方法.mp4 13、【扣子Coze自动化]一天500条文案详细思路--引入自定义插件.mp4 14、【扣子Coze自动化]万能自定义扣子插件--小白也能轻松搞定代码逻辑18:08.mp4 15、【扣子Coze自动化]获取官方apikey和测试自定义插件.mp4 16、【扣子Coze自动化]coze批处理,一次提炼、润色100条小爆款文案-标题-配音.mp4 17、【附加高级篇-来线下过度]3分钟提炼近百条视频文案介绍-(1).mp4 18、【附加高级篇-来线下过度]实战-3分钟提炼近百条视频文案.mp4 19、【扣子Coze附加高级篇-来线下过度】完结升级润色提炼爆款标题-3分钟提近百条文案 ............... 网盘文件永久链接
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值