2025.2.8——1400

news/2025/2/9 11:37:55/文章来源:https://www.cnblogs.com/jkkk/p/18705913

2025.2.8——1400


A 1400

B 1400

------------------------------------------------

  • 思维+贪心。


A

  1. 入手点是考虑每行/列之和为多少。

B

  1. 较难的贪心。
  2. 入手点是转化问题分析方式:分割为两个数组理解为按顺序向两个空数组添加。

------------------------代码------------------------

A

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST)                         \{                                         \for (int I = ST; I < VEC.size(); I++) \cout << VEC[I] << ' ';            \el;                                   \}void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(10);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n, m;cin >> n >> m;vector<vector<int>> a(n + 1, vector<int>(m + 1));string order;cin >> order;for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)cin >> a[i][j];auto rowsum = [&](int i){int ans = 0;for (int j = 1; j <= m; j++)ans += a[i][j];return ans;};auto colsum = [&](int j){int ans = 0;for (int i = 1; i <= n; i++)ans += a[i][j];return ans;};int sx = 1, sy = 1;for (auto s : order){if (s == 'D')a[sx][sy] = -rowsum(sx);elsea[sx][sy] = -colsum(sy);if (s == 'D')sx++;elsesy++;}a[sx][sy] = -rowsum(n);// bug2(sx, sy);for (int i = 1; i <= n; i++){for (int j = 1; j <= m; j++)cout << a[i][j] << ' ';el;}// for (int i = 1; i <= n; i++)//     bug(rowsum(i));// for (int j = 1; j <= m; j++)//     bug(colsum(j));
}
// void _()
// {
//     int n, m;
//     cin >> n >> m;
//     vector<vector<int>> a(n + 1, vector<int>(m + 1)), f(n + 1, vector<int>(m + 1)); // 1 2
//     string order;
//     cin >> order;//     for (int i = 1; i <= n; i++)
//         for (int j = 1; j <= m; j++)
//             cin >> a[i][j];//     auto rowsum = [&](int i)
//     {
//         int ans = 0;
//         for (int j = 1; j <= m; j++)
//             ans += a[i][j];
//         return ans;
//     };
//     auto colsum = [&](int j)
//     {
//         int ans = 0;
//         for (int i = 1; i <= n; i++)
//             ans += a[i][j];
//         return ans;
//     };//     int sx = 1, sy = 1;
//     f[sx][sy] = 1;
//     int sum = order[0] == 'D' ? rowsum(1) : colsum(1);
//     for (auto s : order)
//     {
//         if (s == 'D')
//             sx++;
//         else
//             sy++;
//         f[sx][sy] = 1;
//     }//     for (int i = 1; i <= n; i++)
//         for (int j = 1; j <= m; j++)
//             if (f[i][j])
//             {
//                 if ((j - 1 > 0 && f[i][j - 1]) || (j + 1 <= m && f[i][j + 1]))
//                     f[i][j] = 2;
//             }//     for (int i = 1; i <= n; i++)
//         for (int j = 1; j <= m; j++)
//             if (f[i][j] == 1)
//                 a[i][j] = sum - rowsum(i);
//     for (int i = 1; i <= n; i++)
//         for (int j = 1; j <= m; j++)
//             if (f[i][j] == 2)
//                 a[i][j] = sum - colsum(j);//     for (int i = 1; i <= n; i++)
//     {
//         for (int j = 1; j <= m; j++)
//             cout << a[i][j] << ' ';
//         el;
//     }
//     for (int i = 1; i <= n; i++)
//         bug(rowsum(i));
//     for (int j = 1; j <= m; j++)
//         bug(colsum(j));
// }

B

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
#define bugv(VEC, ST)                         \{                                         \for (int I = ST; I < VEC.size(); I++) \cout << VEC[I] << ' ';            \el;                                   \}void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(10);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n;cin >> n;int x = 1e12, y = 1e12, res = 0;for (int i = 0; i < n; i++){if (x > y)swap(x, y);int a;cin >> a;if (a <= x)x = a;else if (a > y)x = a, res++;elsey = a;}cout << res;el;
}
// void _()
// {
//     int n;
//     cin >> n;
//     vector<int> s, t;
//     for (int i = 0; i < n; i++)
//     {
//         int x;
//         cin >> x;
//         if (!i)
//             s.push_back(x);
//         else
//         {
//             if (x > s.back())
//                 t.push_back(x);
//             else
//                 s.push_back(x);
//         }
//     }
//     int res = 0;
//     for (int i = 1; i < s.size(); i++)
//         res += s[i] > s[i - 1];
//     for (int i = 1; i < s.size(); i++)
//         res += s[i] > s[i - 1];
//     for (int i = 1; i < t.size(); i++)
//         res += t[i] > t[i - 1];
//     cout << res;
//     el;
// }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/881172.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

⑨也能看懂的 nginx 与 C++ 简易版集成

原理概述 nginx 运行在端口A,转发数据给端口B,C++ 监听端口B的数据。 本文例子 使用 C++ 和 nginx 获取客户端的IP地址 代码 nginx 配置 #user nobody; worker_processes 1;events {worker_connections 1024; }http {include mime.types;default_type application/…

探秘Transformer系列之(1):注意力机制

探秘Transformer系列之(1):注意力机制 0x00 概述 因为各种事情,好久没有写博客了,之前写得一些草稿也没有时间整理(都没有时间登录博客和微信,导致最近才发现好多未读消息和私信,在这里和各位朋友说下万分抱歉)。现在恢复更新,是因为最近有些从非AI领域转过来的新同学…

Windows的MySQL数据库升级(解压包方式)

1、背景描述 原来的 MySQL 在安装时,是最新的稳定版本 5.7.33 。 经过一段时间后,在原来的 MySQL 版本中,发现存在漏洞。 因为 MySQL 的官方补丁,需要 Oracle 的 si 码(Support Identifier),不是免费的。 因此,只好将旧版本(5.7.33)升级到没有漏洞的新版本(5.7.44)…

【数据库架构】基于自主可控数据库实现两地三中心容灾的探索与实践

【摘要】金融行业作为第二批次信创试点单位,在大力推广国产软件的背景下,如何保障业务连续性、满足监管部门RPT及RTO指标是新形势下的重要技术挑战,本文作者结合所在单位案例实践,阐述基于OceanBase分布式数据库实现两地三中心容灾的解决方案,供同行参考。 【作者】陈明福…

小包搜题考试

安规考试懒人专用 一、在应用软件商店搜索小包搜题二、微信中找到题库,在微信中点击打开,点击右上角三个点,选择用其他应用打开三、选择小包搜题,进入之后会自动导入题库并给题库命名(随意起),导入成功之后退出小包搜题四、重新进入小包搜题,点击右上角的录屏搜题五、弹…

Qt监控设备离线检测/实时监测设备上下线/显示不同的状态图标/海康大华宇视华为监控系统

一、前言说明 监控系统中一般有很多设备,有些用户希望知道每个设备是否已经上线,最好有不同的状态图标提示,海康的做法是对设备节点的图标和颜色变暗处理,离线的话就变暗,有可能是加了透明度,而大华的处理是有个清晰的图标表示,上线图标右下角有个绿色指示灯,离线的右下…

VIP视频解析之小工具(免费自取)

我们通常会因为看电影但是需要vip却没有足够生活费去支持的困扰 我就在想有没有白嫖的方法呢(bushi 就在我苦恼的时候我发现了一个方法————就是被称为:解析 的技术这玩意就是最好的选择 但是可能部分人在刚刚接触的时候不会用的于是我就写了一个小软件来支持(只支持wind…

2025年值得推荐的 8 款 WPF UI 控件库

前言 今天大姚给大家分享 8 款开源、美观、功能强大、简单易用的WPF UI控件库,希望可以帮助到有需要的同学。 WPF介绍 WPF 是一个强大的桌面应用程序框架,用于构建具有丰富用户界面的 Windows 应用。它提供了灵活的布局、数据绑定、样式和模板、动画效果等功能,让开发者可以…

github官网运行加速方法

github官网打不开的原因 访问github官网时是直接访问域名即github.com,中间有个域名通过DNS解析的过程,将域名解析为对应的ip地址,其实主要时间都是花在了DNS解析上,导致了github有时候能打开,有时候打不开,有时候访问很慢。 解决方案 1、Windows系统打开cmd,输入下列命…

关于AI生成艺术、自动驾驶汽车和Nutella片

Foto di Barbara Zandoval su Unsplash前言:当前时代人们似乎仍然坚信AI没有人类这样的创造力的!那人类的创造力又是什么呢?不也是从开始拥有认识能力,然后逐渐进化到现在空前的创造力的吗?如果AI也自我进化,创造力又能意味着什么? 我是个万事通。作为一名自由职业的在线…

MathType 7.4下载与安装

《数学公式编辑器(MathType)》 [1]是一款专业的数学公式编辑工具,理科生专用的工具。mathtype公式编辑器能够帮助用户在各种文档中插入复杂的数学公式和符号。 数学公式编辑器工具可以轻松输入各种复杂的公式和符号,与Office文档完美结合,显示效果超好,比Office自带的公式编…

支付流程设计常见问题及最佳实践

在实际操作中,支付流程常常面临诸多问题。本文将深入探讨支付流程设计中的常见问题及其最佳实践,供大家参考。今天聊一下支付流程设计的一些常见总是及最佳实践,包括: 组合支付要不要拆支付流水,前端轮询查哪个域,查询要不要穿透到外部渠道,为什么要做同步受理异步处理,…