当前位置: 首页 > news >正文

笔试——Day46

文章目录

  • 第一题
    • 题目
    • 思路
    • 代码
  • 第二题
    • 题目
    • 思路
    • 代码
  • 第三题
    • 题目
    • 思路
    • 代码

第一题

题目

AOE还是单体?
在这里插入图片描述

思路

贪心

剩余怪物数量 >x时,使用AOE;否则使用单体

代码

#include <iostream>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
int n, x;
int arr[N];
int main()
{cin >> n >> x;for (int i = 1; i <= n; i++)cin >> arr[i];sort(arr + 1, arr + 1 + n);long long ret = 0;int index = max(0, n - x); // 处理 x 过⼤的情况ret += arr[index] * x;for (int i = index + 1; i <= n; i++)ret += arr[i] - arr[index];cout << ret << endl;return 0;
}

第二题

题目

kotori和n皇后

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

思路

统计每一个皇后能攻击的位置,若已经有两个皇后可以相互攻击,则后续结果都为True

代码

#include <iostream>
#include <unordered_set>using namespace std;unordered_set<long long> row; // 标记⾏ y
unordered_set<long long> col; // 标记列 x
unordered_set<long long> dig1; // 标记主对⻆线 y - x
unordered_set<long long> dig2; // 标记副对⻆线 y + xint main()
{int n; cin >> n;int res = 1e5;for(int i = 1; i <= n; i++){int x, y; cin >> x >> y;if(res != 1e5) continue;if(row.count(y) || col.count(x) || dig1.count(y - x) || dig2.count(y + x)){res = i;}row.insert(y); col.insert(x); dig1.insert(y - x); dig2.insert(y + x);}int t; cin >> t;while(t--){int i;cin >> i;if(i >= res) cout << "Yes" << endl;else cout << "No" << endl;}return 0;
}

第三题

题目

NC393 取金币

在这里插入图片描述

思路

动态规划

  • dp[i][j] 表示[i, j] 区间⼀共能获得多少⾦币

代码

class Solution {public:/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可*** @param coins int整型vector* @return int整型*/int arr[110] = { 0 };int dp[110][110] = { 0 };int getCoins(vector<int>& coins) {// write code hereint n = coins.size();arr[0] = arr[n + 1] = 1;for (int i = 1; i <= n; i++) arr[i] = coins[i - 1];for (int i = n; i >= 1; i--) {for (int j = i; j <= n; j++) {for (int k = i; k <= j; k++) {dp[i][j] = max(dp[i][j], dp[i][k - 1] + dp[k + 1][j] + arr[i - 1] * arr[k] * arr[j + 1]);}}}return dp[1][n];}
};
http://www.xdnf.cn/news/1344043.html

相关文章:

  • 恢复性测试:定义、重要性及实施方法
  • 深入解析CNAME记录:域名管理的隐形枢纽
  • 几个element-plus的UI,及环境配置
  • 三格电子——ModbusTCP 转 Profinet 主站网关应用实例
  • 【TrOCR】根据任务特性设计词表vocab.json
  • RabbitMQ面试精讲 Day 27:常见故障排查与分析
  • 【数据结构C语言】顺序表
  • 四十一、【高级特性篇】API 文档驱动:OpenAPI/Swagger 一键导入测试用例
  • Design Compiler:层次模型(Block Abstraction)的简介
  • memcmp 函数的使用及其模拟实现
  • 数学建模--Topsis
  • 分布式与微服务
  • [特殊字符] 潜入深渊:探索 Linux 内核源码的奇幻之旅与生存指南
  • LeetCode Hot 100 第一天
  • 相机曝光调节与自动曝光控制详解
  • AI适老服务暖人心:AI适老机顶盒破数字鸿沟、毫米波雷达护独居安全,银发生活新保障
  • 初识数据结构——Map和Set:哈希表与二叉搜索树的魔法对决
  • 车载以太网SOME/IP协议:面向服务的汽车通信技术详解
  • python-对图片中的人体换背景色
  • Java面试宝典:Redis底层原理(持久化+分布式锁)
  • 机器学习-线性回归
  • [react] class Component and function Component
  • vsCode或Cursor 使用remote-ssh插件链接远程终端
  • 用户登录Token缓存Redis实践:提升SpringBoot应用性能
  • yggjs_rlayout使用教程 v0.1.0
  • unistd.h 常用函数速查表
  • 【Linux仓库】进程的“夺舍”与“飞升”:exec 驱动的应用现代化部署流水线
  • Elasticsearch倒排索引和排序
  • Elasticsearch核心概念
  • 【机器学习深度学习】大模型分布式推理概述:从显存困境到高并发挑战的解决方案