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. 思科命令 service password-encryption

    service password-encryption 将会把所有password用思科私有方式加密, 标记是 7,show run 查看密码时,5为md5加密结果即secret, no servic ...

  2. Nessus 8.2.3无IP限制VM版虚拟机

    根据“西门吹雪”http://ximcx.cn/m/?post=151的文章自己下载配置的过程 VM版本>=12都行,我用的是VM14 下载地址 https://moehu-my.sharepo ...

  3. CF1227F2 Wrong Answer on test 233 (Hard Version)

    题意 \(n\)道题,每道题有\(k\)种选项,其中第\(i\)道题正确答案是\(a_i\),但是填答案的时候填错啦,第一道题的选择填到了第二道题...第\(n\)道题的选择填到了第一道题,求在\(k ...

  4. 给静态网站的链接添加nofollow属性

    给网站的链接添加nofollow属性对SEO非常有效,如果是动态网站,实现的方法比较多,但是对于静态网站来说只能借助CSS或者JS来实现,单纯的CSS实现需要覆盖所有的链接出现位置:JS与CSS结合则 ...

  5. Codeforces 1304E. 1-Trees and Queries 代码(LCA 树上两点距离判奇偶)

    https://codeforces.com/contest/1304/problem/E #include<bits/stdc++.h> using namespace std; typ ...

  6. Python论做游戏外挂,Python输过谁?

    玩过电脑游戏的同学对于外挂肯定不陌生,但是你在用外挂的时候有没有想过如何做一个外挂呢? 我打开了4399小游戏网,点开了一个不知名的游戏,唔,做寿司的,有材料在一边,客人过来后说出他们的要求,你按照菜 ...

  7. 关于Javascript闭包的理解

    以下内容属个人理解,如有看不明白或漏洞之处,纯属水平不佳,还望见谅. 关于闭包,高程里的定义是:指有权访问另一个函数作用域中的变量的函数.创建闭包最常见的方法就是在一个函数的内部再创建一个函数. 这里 ...

  8. gulp常用插件之browser-sync使用

    更多gulp常用插件使用请访问:gulp常用插件汇总 browser-sync这是一个可以在多端(pc.移动.平板)实时监测文件修改,自动刷新浏览器的工具.其实这并不是转给gulp使用的,在其它构建工 ...

  9. the import javax.jms cannot be resolved问题

    JDK中并没有javax.jms包,你需要一个JMS实现(比如:activemq),并确认相应的jar被包含在CLASSPATH中. http://activemq.apache.org/ 5.5.0 ...

  10. @RendSection{"scripts",require:false}的作用

    MVC视图中,Javascripts代码被放于下面的Razor代码中(@section Scripts{}). 好处:在视图进行JavaScript编程时,是一个很好的实践,在共享视图(_Layout ...