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

Codeforces Round 1024 (Div. 2)

Problem - A - Codeforces

思维题:

如果n不能整除p,就会多出一部分,这个部分可以作为调和者,使整个数组符合要求。

如果n能整除p,没有调和空间,只有看n/p*q==m

来看代码:

#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
int main()
{int t;cin >> t;while (t--){int n, m, p, q;cin >> n >> m >> p >> q;if (n % p == 0&&n/p*q!=m){cout << "NO" << endl;}else{cout << "YES" << endl;}}}

Problem - B - Codeforces

题目大意:

数组的第一个数可以通过对数组任意数乘-1从而成为大小为n的数组 第n/2大的数吗?

解法:

为了方便处理,把数都先变为正数,第一个数赋值给man后,对数组arr进行从小大到大排序

查看man在排序后位置在哪?

1.在中位数之前,解法简单:不断让比man大的数乘-1变得比man小,就能让man到中位数的位置。

2.在中位数之后,此时无论把比man大的数*-1还是比man小的数*-1都不行,怎么办?

只有对所有数*-1,看看man倒着数是不是在中位数的位置

来看代码:

#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
int main()
{int t;cin >> t;while (t--){int n;cin >> n;vector<int>arr(n);for (int i = 0; i < n; i++){cin >> arr[i];arr[i] = abs(arr[i]);}//一步登天int man = arr[0];int exp = (n + 1) / 2;exp -= 1;int flag = 0;sort(arr.begin(), arr.end());int now = 0;for (int i = 0; i < n; i++){if (arr[i] == man){now = i;break;}}if (now <= exp||n-1-now==exp){flag = 1;}else{flag = 0;}if (flag){cout << "YES" << "\n";}else{cout << "NO" << "\n";}}}

Problem - C - Codeforces

一道构造题目,怎么排,才能把子网格相加的mex得到最大呢?

因为有mex机制在,大的数在内部起不到作用,所以
大的数在外围,小的数在内部。最小的数0放在最中间,这样能保证最多的mex能包括到它。

解法:

从大到小,从外向内 蛇形放数

#include <iostream>
#include <vector>
using namespace std;vector<vector<int>> constructGrid(int n)
{vector<vector<int>>grid(n, vector<int>(n, -1));int current = n * n - 1;int x = 0;int y = n - 1;int dir = 0;vector<int>dx = { 0,1,0,-1};vector<int>dy = { -1,0,1,0 };//左 下 右 上int next_x;int next_y;for (int i = 0; i < n * n - 1; i++){grid[x][y] = current--;next_x = x + dx[dir];next_y = y + dy[dir];if (next_x < 0 || next_x >= n || next_y < 0 || next_y >= n || grid[next_x][next_y] != -1){dir = (dir + 1) % 4;next_x = x + dx[dir];next_y = y + dy[dir];}x = next_x;y = next_y;}grid[n / 2][n / 2] = 0; // 中心位置填0return grid;
}int main() {int t;cin >> t;while (t--){int n;cin >> n;auto grid = constructGrid(n);for (const auto& row : grid) {for (int num : row) {cout << num << " ";}cout << endl;}}return 0;
}

http://www.xdnf.cn/news/719497.html

相关文章:

  • 山东省申报高级职称、正高级职称条件(工业、信息化方向)
  • 大数据如何赋能市场情报分析?——精准决策,从数据开始
  • echarts主题切换实现
  • 多模态融合新方向:光学+AI如何智能分拣,提升塑料回收率?
  • 基于卫星遥感数据识别互花米草及原生植被分布及生长的技术原理、关键方法
  • 利用TOA与最小二乘法直接求解
  • React从基础入门到高级实战:React 生态与工具 - React 国际化(i18n)
  • [学习]C++ 模板探讨(代码示例)
  • Python模块中__all__变量失效问题深度解析
  • 虚幻基础:模型
  • 鲜羊奶对青少年心理健康的 “技术向” 营养支持
  • day31 5月29日
  • python打卡第36天
  • WPF中自定义消息弹窗
  • 小白畅通Linux之旅-----Linux安全管理
  • Ubuntu系统下Docker部署Dify保姆级教程:实现内网穿透远程访问
  • 超声波清洗机的作用是什么?使用超声波清洗机可以去除毛刺吗?
  • 非常好看网站维护带倒计时模板+维护结束模板
  • [嵌入式实验]实验一:点亮LED
  • Cisco Packer Tracer 中 VLAN 与三层交换机
  • UDS TP层参数
  • 【面板数据】各地区新型数字基础设施数据集(2002-2025年)
  • Day 39
  • 结构体对齐和结构体相关宏
  • day39 图像数据与显存
  • Cadence Innvous导出GDS没有STDCELL/IO/NET/VIA问题的解决方法
  • 输电线路的“智慧之眼”:全天候可视化监测如何赋能电网安全运维
  • Cmake编译glog成功并在QT中测试成功步骤
  • Mac本地安装MySQL jdbc Driver
  • 性能测试-jmeter实战1