A - Reign

题面

题解

最大子段和+\(DP\)。

预处理两个数组:

  • \(p[i]\)表示 \(i\) 之前的最大子段和。
  • \(l[i]\)表示 \(i\) 之后的最大子段和。

最后直接输出即可。

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#define int long long
#define gI gi
#define itn int
#define File(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout) using namespace std; inline int gi()
{
int f = 1, x = 0; char c = getchar();
while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
return f * x;
} int t, n, m, k, ans, a[100003], p[100003], l[100003]; signed main()
{
//File("REIGN");
t = gi();
while (t--)
{
n = gi(), k = gi();
for (itn i = 1; i <= n; i+=1) a[i] = gi();
memset(p, 0, sizeof(p)); memset(l, 0, sizeof(l));
ans = -0x7fffffff;
for (itn i = 1; i <= n; i+=1)
{
if (p[i - 1] < 0) p[i] = a[i];
else p[i] = p[i - 1] + a[i];
}
p[0] = -0x7fffffff;
for (itn i = 1; i <= n; i+=1) p[i] = max(p[i], p[i - 1]);
for (int i = n; i >= 1; i-=1)
{
if (l[i + 1] < 0) l[i] = a[i];
else l[i] = l[i + 1] + a[i];
}
l[n + 1] = -0x7fffffff;
for (itn i = n; i >= 1; i-=1) l[i] = max(l[i], l[i + 1]);
for (int i = 1; i < n - k; i+=1) ans = max(ans, p[i] + l[i + k + 1]);
printf("%lld\n", ans);
}
return 0;
}

C - Strongly Connected City

题面

题意简述

给定\(n\)条水平的单向街道和\(m\)条竖直单向的街道,其交点共有\(n \times m\)个,问这些节点是否都能互相到达。

\(2 \leq n,m \leq 20\)

题解

只需要判断最外圈是不是一个环即可。

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <string>
#define gI gi
#define itn int
#define File(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout) using namespace std; inline int gi()
{
int f = 1, x = 0; char c = getchar();
while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
return f * x;
} bool fl = false;
int n, m, a[25][25][2], tot, vis[25][25];
char s[2][25]; int main()
{
n = gi(), m = gi();
string s[3];
cin >> s[1];
if (s[1][0] == s[1][n - 1]) {puts("NO"); return 0;}
cin >> s[2];
if (s[1][0] == '<' && s[2][0] == '^') {puts("NO"); return 0;}
if (s[1][0] == '>' && s[2][m - 1] == '^') {puts("NO"); return 0;}
if (s[1][n - 1] == '<' && s[2][0] == 'v') {puts("NO"); return 0;}
if (s[1][n - 1] == '>' && s[2][m - 1] == 'v') {puts("NO"); return 0;}
puts("YES");
return 0;
}

F - Chef and Digit Jumps

题面

题解

\(BFS\)裸题。

有一个优化:让每一个点在队列中只会出现一次,优化时间复杂度。

注意一些细节。

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <queue>
#define gI gi
#define itn int
#define File(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout) using namespace std; inline int gi()
{
int f = 1, x = 0; char c = getchar();
while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
return f * x;
} char s[100003];
int n, m, len, p, ans, sum, b[1000003], vis[100003];
vector <int> a[15];
queue <int> q; int main()
{
//File("DIGJUMP");
scanf("%s", s + 1);
len = strlen(s + 1);
for (int i = 1; i <= len; i+=1)
{
a[s[i] - '0'].push_back(i);
}
q.push(1); b[1] = 0;
while (!q.empty())
{
int x = q.front(); q.pop();
if (x == len) break;
int y = s[x] - '0';
if (!vis[y])
{
vis[s[x] - '0'] = 1;
for (int i = 0; i < a[y].size(); i+=1)
{
int z = a[y][i];
if (z != x && b[z] == 0)
{
b[z] = b[x] + 1;
q.push(z);
}
}
}
if (x - 1 >= 1 && b[x - 1] == 0) {b[x - 1] = b[x] + 1; q.push(x - 1);}
if (x + 1 <= len && b[x + 1] == 0) {b[x + 1] = b[x] + 1; q.push(x + 1);}
}
printf("%d\n", b[len]);
return 0;
}

总结

这次做题做得很不理想。

\(T3\)时间复杂度算错浪费了很多时间。

\(T1\)想了很久才想到正解。

要多多练习,才能有提高啊!

NOIP做题练习(day2)的更多相关文章

  1. noip做题记录+挑战一句话题解?

    因为灵巧实在太弱辽不得不做点noip续下命QQAQQQ 2018 积木大赛/铺设道路 傻逼原题? 然后傻逼的我居然检查了半天是不是有陷阱最后花了差不多一个小时才做掉我做过的原题...真的傻逼了我:( ...

  2. NOIP做题练习(day1)

    A - Xenny and Alternating Tasks 题面 题解 枚举第一天是谁做,将两个答案取\(min\)即可. 代码 #include <iostream> #includ ...

  3. $NOIp$做题记录

    虽然去年做了挺多了也写了篇一句话题解了但一年过去也忘得差不多了$kk$ 所以重新来整理下$kk$ $2018(4/6$ [X]积木大赛 大概讲下$O(n)$的数学方法. 我是从分治类比来的$QwQ$. ...

  4. NOIP做题练习(day4)

    A - 同花顺 题面 题解 30分做法 爆搜即可. 60分做法 去重+贪心. 100分做法 去重+贪心后,我们要寻找一段符合条件的最长同花上升子序列 \(L\),\(n-L\) 即为所求的答案. 首先 ...

  5. NOIP做题练习(day5)

    A - 中位数图 题面 题解 先找出题意中的\(b\)所在的位置. 再以这个位置为中心,向右\(for\)一遍有多少个大于/小于该数的数 大于就\(++cs\) 小于就\(--cs\). 因为这个数是 ...

  6. NOIP做题练习(day3)

    A - 军队 问题描述 给定一个有 \(n\) 个队伍的人组成的序列,第 \(i\) 个队伍 \(i\) 有 \(s[i]\)个人组成,一个 \(l\) 到 \(r\)的子序列是合法的,当且仅当\(( ...

  7. NOIP初赛:完善程序做题技巧

    最近写的文章好像还很多的.那么今天我们来讨论NOIP初赛的题型--完善程序.完善程序相对是比较难的题目了.全卷100分,完善程序占了大概26分,占比非常大.如果和英语考试试卷做比较,相当于首字母填空( ...

  8. [日记&做题记录]-Noip2016提高组复赛 倒数十天

    写这篇博客的时候有点激动 为了让自己不颓 还是写写日记 存存模板 Nov.8 2016 今天早上买了两个蛋挞 吃了一个 然后就做数论(前天晚上还是想放弃数论 但是昨天被数论虐了 woc noip模拟赛 ...

  9. CodeM美团点评编程大赛复赛 做题感悟&题解

    [T1] [简要题意]   长度为N的括号序列,随机确定括号的方向:对于一个已确定的序列,每次消除相邻的左右括号(右左不行),消除后可以进一步合并和消除直到不能消为止.求剩下的括号的期望.\(N \l ...

随机推荐

  1. jquery的封装与对象学习

    1.封装学习 /// <reference path="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" /> ...

  2. PAT 基础编程题目集 6-10 阶乘计算升级版 (20 分)

    本题要求实现一个打印非负整数阶乘的函数. 函数接口定义: void Print_Factorial ( const int N ); 其中N是用户传入的参数,其值不超过1000.如果N是非负整数,则该 ...

  3. ArcScene 创建三维模型数据

    1. 拉伸 添加面元素图层 在图层上右键----属性 , 设置拉伸值,可以输入固定值或者选择字段值. 2. 导入   3DMAX 的 3ds 文件,和 Google SketchUp 的skp文件, ...

  4. Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache的类型初始值设定项引发异常。 ---> System.IO.FileLoadException: 未能加载文件或程序集

    场景: 安装程序到全新的环境的电脑时中(此时已经安装了能正常安装程序电脑的环境) 完整错误: Application_ThreadException:System.TypeInitialization ...

  5. MySql 小表驱动大表

    在了解之前要先了解对应语法 in 与 exist. IN: select * from A where A.id in (select B.id from B) in后的括号的表达式结果要求之输出一列 ...

  6. c++ md5算法实现(转)

    原文链接:C++计算文件的MD5值 其他:c++输入文件流ifstream用法详解

  7. StaticFileMiddleware 解析

       说明:由于部分产品没有静态资源的管理,我突然想到能不能用现有的静态文件中间件的功能调整一下实现多组织件上传文件的隔离呢?那第一步先看懂   StaticFileMiddleware做了什么吧. ...

  8. django csrf 中间件

    CSRF和中间件 CSRF使用 说明csrf存在cookie中 全局使用 MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', ...

  9. Leetcode Week3 Merge Two(k) Sorted Lists

    Question Q1.Merge two sorted linked lists and return it as a new list. The new list should be made b ...

  10. ALSA lib-io plugin

    https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_external_plugins.html External Plugin: I/O Plugin ...