SMU Summer 2023 Contest Round 3

A. Curriculum Vitae

题意就是要求\(1\)后面不能有\(0\)的情况下的子序列最长长度, 也就是求一个最长不下降子序列,不过由于这是个\(01\)序列,也可以分别做一个前缀和求出\(0\)的数量,后缀和求\(1\)的数量,最后跑一遍循环,找一个最大值即可,

这里我是\(dp\)写的一个最长不下降子序列

#include  <bits/stdc++.h>
#define endl '\n'
#define int long long using namespace std; int n,m;
void solve(){
cin >> n;
vector<int> s(n);
int one = 0;
for(auto &i : s){
cin >> i;
}
vector<int> dp(n);
int ans = 0;
for(int i = 0;i < n;i ++){
dp[i] = 1;
for(int j =0; j < i;j ++){
if(s[i] >= s[j]){
dp[i] = max(dp[j] + 1, dp[i]);
}
}
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
// cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}
/*
*/

B. Math Show

这题由于数据范围很小,可以直接暴力贪心求解

#include  <bits/stdc++.h>
#define endl '\n'
#define int long long
#define all(a) (a).begin(),(a).end() using namespace std; int n,m;
int match[N];
void solve(){
int k,M;
cin >> n >> k >> M;
vector<int> a(k + 1);
int sum = 0;
for(int i = 1;i<= k;i++){
cin >> a[i];
sum += a[i];
}
sort(all(a)); int ans = 0;
for(int i = 0;i <= n;i ++){
int score = i * k + i, t = sum * i, r = n - i;
/*
score 是完成i个人时的初始分数,因为完成一个人要+1,所以这里是直接+i;
t是完成i个人所消耗的时间,当t大于M时就可以直接退出;
r是目前为止还有几个人任务未完成.
*/
if(t > M ) break;
for(int j = 1;j <= k;j ++){
if(t >= M) break;
for(int p = 1;p <= r;p ++){
t += a[j];
if(t > M) break;
score ++;
}
}
ans = max(ans, score);
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
// cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}
/*
*/

C. Four Segments

题意翻译过来就在一个序列里找到\(i,j,k\)三个分界点使得\(sum(0, i) - sum(i, j) + sum(j, k) - sum(k, n)\)的值最大,\(sum( i,j)\)就是\(j\)的前缀和减去\(i\)的前缀和,如果直接暴力三层循环的话,时间肯定是不够的,这里我们可以发现这个公式前半部分\(sum(0,i) - sum(i,j)\)与它的的后半部分\(sum(j,k) - sum(k,n)\)在\(j\)是一个确定的值时其实是互不影响的,所以我们单独循环\(j\),然后分别去循环\(i\)和\(k\),找到两个部分的最大值时的\(i,k\)的值即可.

#include  <bits/stdc++.h>
#define endl '\n'
#define int long long
#define all(a) (a).begin(),(a).end() using namespace std; int n,m;
void solve(){
cin >> n;
vector<int> a(n + 1), pre(n + 1);
for(int i = 1;i <= n;i ++){
cin >> pre[i];
pre[i] += pre[i - 1];
}
int ans = -LLONG_MAX; int ansi, ansk, ansj;
for(int j = 0;j <= n;j ++){
int sum1 = -inf, sum2 = -inf, sum;
int si,sk;
for(int i = 0;i <= j;i ++){
if(pre[i] - (pre[j] - pre[i]) > sum1){
sum1 = pre[i] - (pre[j] - pre[i]);
si = i;
}
} for(int k = j;k <= n;k ++){
if(pre[k] - pre[j] - (pre[n] - pre[k]) > sum2){
sum2 = pre[k] - pre[j] - (pre[n] - pre[k]);
sk = k;
}
} sum = sum1 + sum2;
if(sum > ans){
ans = sum ;
ansi = si, ansj = j, ansk = sk;
}
}
cout << ansi << ' ' << ansj << ' ' << ansk << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
// cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}
/*
*/

D. Monitor

题意就是给出\(q\)个坏掉的像素点坐标和坏掉的时间,当这些点构成一个\(k*k\)的正方形时,说明显示屏会坏掉,而我们要找到它坏掉时的最小时间,如果\(q\)个坐标都不能构成这个正方形,则说明没坏,输出\(-1\).

做法是二分+二维前缀和,即先对每个坏掉的像素点坏掉的时间排序,然后去对这\(q\)个像素点二分,每次去检查它是否能构成一个\(k*k\)的正方形,不能就往后寻找,最后\(l > q\)的话则说明\(q\)个像素点都不能构成此正方形.

#include  <bits/stdc++.h>
#define endl '\n'
#define int long long
#define all(a) (a).begin(),(a).end() using namespace std; int n,m;
struct Node{
int x,y,t;
};
vector<vector<int>> gg(501,vector<int> (501));
void solve(){
int k , q;
cin >> n >> m >> k >> q;
vector<Node> a(q + 1);
for(int i = 1;i <= q;i ++)
cin >> a[i].x >> a[i].y >> a[i].t; sort(a.begin() + 1,a.end(),[](Node a, Node b){return a.t < b.t;});
//这里如果你是从1开始输入的话,排序一定要从1开始排,因为它的t是可以等于0的 auto check = [&](){
for(int i = k;i <= n;i ++)
for(int j = k; j <= m;j ++)
if(gg[i][j] - gg[i - k][j] - gg[i][j - k] + gg[i - k][j - k] == k * k)
return true;
return false;
}; int l = 1, r = q;
while(l <= r){
int mid = (l + r) >> 1; vector<vector<int>> g(n + 1, vector<int> (m + 1, 0));
for(int i = 1;i <= mid;i ++)
g[a[i].x][a[i].y] = 1; for(int i = 1;i <= n;i ++)
for(int j = 1; j <= m;j ++)
gg[i][j] = gg[i - 1][j] + gg[i][j - 1] - gg[i - 1][j - 1] + g[i][j]; if(check())
r = mid - 1;
else
l = mid + 1;
} cout << (l > q ? -1 : a[l].t) << endl; }
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
// cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}
/*
*/

SMU Summer 2023 Contest Round 3的更多相关文章

  1. 2015 Astar Contest - Round 3 题解

    1001 数长方形 题目大意 平面内有N条平行于坐标轴的线段,且不会在端点处相交 问共形成多少个矩形 算法思路 枚举4条线段的全部组合.分别作为矩形四条边.推断是否合法 时间复杂度: O(N4) 代码 ...

  2. Contest Round #451 (Div. 2)F/Problemset 898F Restoring the Expression

    题意: 有一个a+b=c的等式,去掉两个符号,把三个数连在一起得到一个数 给出这个数,要求还原等式,length <= 1e6 三个数不能含有前导0,保证有解 解法: 铁头过题法,分类然后各种判 ...

  3. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Sending messages to non-windowed applications -- AllocateHWnd, DeallocateHWnd

    http://delphi.about.com/od/windowsshellapi/l/aa093003a.htm Page 1: How Delphi dispatches messages in ...

  5. Codeforces 240 F. TorCoder

    F. TorCoder time limit per test 3 seconds memory limit per test 256 megabytes input input.txt output ...

  6. cf499B-Lecture 【map】

    http://codeforces.com/problemset/problem/499/B B. Lecture     You have a new professor of graph theo ...

  7. Codeforces 240F. TorCoder 线段树

    线段树统计和维护某一区间内的字母个数.. . . F. TorCoder time limit per test 3 seconds memory limit per test 256 megabyt ...

  8. 物联网学生科协第三届H-star现场编程比赛

    问题 A: 剪纸片 时间限制: 1 Sec 内存限制: 128 MB 题目描写叙述 这是一道简单的题目,假如你身边有一张纸.一把剪刀.在H-star的比赛现场,你会这么做: 1. 将这张纸剪成两片(平 ...

  9. [cf contest 893(edu round 33)] F - Subtree Minimum Query

    [cf contest 893(edu round 33)] F - Subtree Minimum Query time limit per test 6 seconds memory limit ...

  10. 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest

    题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...

随机推荐

  1. 配置pod拉取harbor容器镜像仓库私有镜像:secret保存账号密码

    目录 一.系统环境 二.前言 三.Docker-Registry类型的Secret简介 四.镜像仓库简介 五.搭建Harbor容器镜像仓库 5.1 安装Harbor 5.2 创建项目 5.3 推送镜像 ...

  2. frp内网穿透:基于centos8 云服务器和debian12客户端服务器

    前言 入了一台本地工控机盒子,刷成了debian12系统,性能比云服务器要好一点,现在想要远程访问这台盒子,但是盒子又没有公网地址,所以想通过内网穿透的方式,通过云服务器转发请求实现内网穿透.原来体验 ...

  3. javascript的内存(垃圾)回收机制?

    垃圾回收机制 1.js中的内存回收 在js中,垃圾回收器每隔一段时间就会找出那些不再使用的数据,并释放其所占用的内存空间. 以全局变量和局部变量来说,函数中的局部变量在函数执行结束后这些变量已经不再被 ...

  4. SpringBoot 整合EasyExcel 获取动态Excel列名

    导读 最近负责消息网关,里面有个短信模板导入功能,因为不同模板编号对应不同参数,导入后的数据定时发送,涉及到Excel中列名不固定问题,于是想根据列名+值,组合成一个大JSON,具体代码如下. 引入依 ...

  5. Oracle自定义数据类型

    1 CREATE OR REPLACE FUNCTION split(p_str IN clob, 2 p_delimiter IN VARCHAR2 default (',') --分隔符,默认逗号 ...

  6. mysql 授权远程连接

    解决方案 改表法 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 &quo ...

  7. THM-Skynet-Writeup

    通过学习相关知识点:攻破Linux目标机器并完成提权操作. 部署并渗透目标机器 step1 使用Nmap扫描端口 nmap -p- -sC -sV -T4 -v 10.10.164.81 139/44 ...

  8. 利用Selenium和PhantomJS绕过接口加密的技术探索与实践

    selenium+phantomjs绕过接口加密 我们为什么需要selenium 之前我们讲解了 Ajax 的分析方法,利用 Ajax 接口我们可以非常方便地完成数据的爬取.只要我们能找到 Ajax ...

  9. 在宝塔上配置打包好的vue3项目

    配置文件如下 server{ listen 80; server_name gongchang.365cb.cn; index index.html index.htm default.php def ...

  10. ComfyUI进阶:Comfyroll插件 (三)

    前言: 学习ComfyUI是一场持久战,而Comfyroll 是一款功能强大的自定义节点集合,专为 ComfyUI 用户打造,旨在提供更加丰富和专业的图像生成与编辑工具.借助这些节点,用户可以在静态图 ...