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. 原生js或者是es中让人厌恶的一些地方

    js总体来说,是个不错的语言,最大的好处的是简单. 但这个基于es6的一些js也有一些非常怪异的写法,这是非常令人憎恶的地方. c++总体上也算不错,但为什么不是很受欢迎,因为它把自己搞得太复杂了,复 ...

  2. Markdown常用语法详解

    背景知识 什么是html html是一种网页标记语言.我们平常见到的那么好看的网页就是通过html语言来编写的. html语言举例: <h1>hello world</h1> ...

  3. C++面向对象多级菜单向Arduino的移植

    前段时间写了一篇文章<C++面向对象语言自制多级菜单>,文中指出了可以将HeleMenu库进行移植,现已完成技术思路,特此记录. 一.特性 基本与上一篇文章指出的一致,只是将菜单显示和响应 ...

  4. FPGA对EEPROM驱动控制(I2C协议)

    本文摘要:本文首先对I2C协议的通信模式和AT24C16-EEPROM芯片时序控制进行分析和理解,设计了一个i2c通信方案.人为按下写操作按键后,FPGA(Altera EP4CE10)对EEPROM ...

  5. Linux设备模型:2、基本对象 Kobject、Kset、Ktype

    原文:http://www.wowotech.net/device_model/kobject.html 作者:wowo 发布于:2014-3-7 0:25 分类:统一设备模型 前言 Kobject是 ...

  6. HTTP事务理解

    借图: 首先三次握手理解: TCP三次握手好比两个对话, 第一次握手:甲给乙一直发送信息,乙没有回应,甲不知道乙有没有收到信息 第二次握手:乙收到信息,然后再给甲回信息,此时甲知道乙收到信息,但乙不知 ...

  7. v-model 的原理?

    我们在 vue 项目中主要使用 v-model 指令在表单 input.textarea.select 等元素上创建双向数据绑定,我们知道 v-model 本质上不过是语法糖,v-model 在内部为 ...

  8. wangEditor增加源码模式,添加查看源码功能

    wangEditor是一款轻量级的富文本编辑器.使用还比较方便,但是缺少查看源码模式,需要我们自定义一个menu给增加查看源码模式 下面是wangEditor增加源码模式的代码: <!DOCTY ...

  9. 基于Java网络书店商城设计实现(源码+lw+部署文档+讲解等)

    系统介绍: 随着科学技术的飞速发展,各行各业都在努力与现代先进技术接轨,通过科技手段提高自身的优势:对于网络书店商城当然也不能排除在外,随着网络技术的不断成熟,带动了网络书店商城,它彻底改变了过去传统 ...

  10. 国赛2024 simple_php(三种方法)

    <?php ini_set('open_basedir', '/var/www/html/'); error_reporting(0); if(isset($_POST['cmd'])){ $c ...