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. css揭秘 一

    当某些值相互依赖是,应该把它们的相互关系用代码表达出来 font-size: 20px; line-height: 1.5; // 行高是字体的1.5倍 当改变某个参数时候,做到只改尽量少的地方,最好 ...

  2. 3、const与constexpr

    初遇到constexpr真的是有点懵比,看了很多博客也没看懂,不知道是我太笨,还是别人写的太深奥?总之经过一番折腾算是入门了.一下是我个人总结,有不对的地方望指出. 一.学习const与constex ...

  3. Android View框架的layout机制

    概述 Android中View框架的工作机制中,主要有三个过程: 1.View树的测量(measure) Android View框架的measure机制 2.View树的布局(layout)Andr ...

  4. 0级搭建类006-Oracle Solaris 安装 (10.13) 公开

    项目文档引子系列是根据项目原型,制作的测试实验文档,目的是为了提升项目过程中的实际动手能力,打造精品文档AskScuti. 项目文档引子系列目前不对外发布,仅作为博客记录.如学员在实际工作过程中需提前 ...

  5. 实现Windows数据更新

    一.枚举 枚举是一组描述性的名称 定义一组有限的值,不能包含方法 对可能的值进行约束 .定义枚举类 public enum Gender { Male,Female } .使用枚举表示整数值 publ ...

  6. int long的数据范围

    java 整数型 byte 1字节   -128~127  -2^7~2^7-1 short 2字节 -32768~32767 int  4个字节 -2147483648~2147483647  -2 ...

  7. 我的python笔记06

    面向对象学习 本节内容:   面向对象编程介绍 为什么要用面向对象进行开发? 面向对象的特性:封装.继承.多态 类.方法.     引子 你现在是一家游戏公司的开发人员,现在需要你开发一款叫做< ...

  8. Myeclipse连接Mysql数据库时报错:Error while performing database login with the pro driver:unable

    driver template: Mysql connector/j(下拉框进行选择) driver name: 任意填,最好是数据库名称,方便查找 connection URL: jdbc:mysq ...

  9. Harvard's CS50

    最近看了哈佛大学David主讲的计算机科学入门,给我一个最大的感受是计算机编程语言真的不重要,重要的是编程者的思想. 1.同一个问题可以就Scratch解决,也可以用C,用Python,用JavaSc ...

  10. appium+android测试环境安装

    1. jdk配置 一.背景 JDK已经更新到12了,但是由于很多工具仍然未及时更新,故推荐最稳定的JDK版本1.8.x: JDK需要配置通常情况下,JDK配置分为三项: JAVA_HOME:某些软件仍 ...