博客
关于我
【DG特长生2018 T4】【SSL 2888】【luogu P2003】平板游戏问题 / PLATFORME 平板
阅读量:338 次
发布时间:2019-03-04

本文共 1488 字,大约阅读时间需要 4 分钟。

平板游戏问题:计算所需支柱总长度

问题背景

在平板游戏中,有一些横放的木板,每个木板需要支撑两端。这些支撑可以搭在木板下方,如果下方没有支撑就直接搭在地板上。我们的任务是计算所有支柱的总长度。

思路解析

解决这个问题的思路是通过模拟每个木板的位置,并记录每个x坐标上木板的高度。然后,对这些木板按高度从大到小排序。每个木板的支柱长度即为其高度减去下一个木板的高度。将所有这样的长度相加即可得到总支柱长度。

代码实现

#include 
#include
#include
using namespace std;struct block { int y, x1, x2;};struct bord { int y, num, important;};bool cmp(bord x, bord y) { if (x.y == y.y) return x.important > y.important; return x.y > y.y;}int main() { // 读取输入 int n; scanf("%d", &n); // 初始化数据结构 int number[10001]; int ans = 0; struct bord x[10001][104]; for (int i = 1; i <= n; ++i) { int y, x1, x2; scanf("%d %d %d", &y, &x1, &x2); x2--; // 调整右端点 for (int j = x1; j <= x2; ++j) { // 记录每个x坐标的木板信息 x[j][number[j]] = bord{y, i, 0}; if (j == x1 || j == x2) { // 标记边缘木板 x[j][number[j]].important = 1; important_num[j]++; // 记录重要木板数量 } } } // 处理每个x坐标的木板 for (int i = 1; i <= 10000; ++i) { if (!important_num[i]) continue; // 对木板按高度排序 sort(x[i] + 1, x[i] + number[i] + 1, cmp); // 计算支柱长度 for (int j = 1; j < number[i]; ++j) { if (x[i][j].important) { ans += x[i][j].y - x[i][j + 1].y; } } } printf("%d", ans); return 0;}

总结

通过对每个木板的高度进行排序,计算相邻高度之差,我们可以轻松得到所有支柱的总长度。这种方法确保了计算的准确性和高效性,适用于处理各种规模的平板游戏问题。

转载地址:http://jgvh.baihongyu.com/

你可能感兴趣的文章
Nmap渗透测试指南之指纹识别与探测、伺机而动
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>