Day 26 - 模拟赛

1|0热门景点(hot)

题目描述

输入格式

输出格式

input1

10 5 1 7 4 0 9 4 8 8 2 4 6 6 2 8 2 2 3 6 7 8

output1

Y N Y N Y

数据范围

#include<iostream> #include<cstdio> #include<ctime> using namespace std; #define MAXN 5000005 int read() { int x = 0; bool f = 0; char ch = getchar(); while(ch < 48 || ch > 57) { if(ch == 45) f = 1; ch = getchar(); } while(ch >= 48 && ch <= 57) { x = (x << 3) + (x << 1) + (ch - 48); ch = getchar(); } return f ? -x : x; } int n, q, a[MAXN], pl[MAXN], pr[MAXN], cnt = 0, l, r; struct node { int lm, rm; } b[MAXN]; int main() { freopen("hot.in", "r", stdin); freopen("hot.out", "w", stdout); n = read(); q = read(); for(int i = 1; i <= n; i ++) a[i] = read(); pl[1] = 1; for(int i = 2; i <= n; i ++) if(a[i] <= a[i - 1]) pl[i] = pl[i - 1]; else pl[i] = i; pr[n] = n; for(int i = n - 1; i >= 1; i --) if(a[i] <= a[i + 1]) pr[i] = pr[i + 1]; else pr[i] = i; // for(int i = 1; i <= n; i ++) cout << pl[i] << " "; // cout << "\n"; // for(int i = 1; i <= n; i ++) cout << pr[i] << " "; // cout << "\n"; while(q --) { l = read(); r = read(); if(pr[l] >= pl[r]) printf("Y\n"); else printf("N\n"); } // for(int i = 1; i <= n; i ++) // if(a[i] >= a[i - 1]) pl[i] = pl[i - 1] + 1; // else pl[i] = 1; // for(int i = n; i >= 1; i --) // if(a[i] >= a[i + 1]) pr[i] = pr[i + 1] + 1; // else pr[i] = 1; //// for(int i = 1; i <= n; i ++) cout << pl[i] << " "; //// cout << "\n"; //// for(int i = 1; i <= n; i ++) cout << pr[i] << " "; //// cout << "\n"; // int tmp = 1; while(pl[tmp] > pl[tmp - 1]) tmp ++; //// cout << tmp - 1 << "\n"; // pl[n + 1] = 1; // for(int i = tmp - 1; i <= n; ) { // b[++ cnt].lm = i - pl[i] + 1, b[cnt].rm = i + pr[i] - 1; // i += pr[i]; while(pl[i + 1] != 1) i ++; // } //// for(int i = 1; i <= cnt; i ++) cout << b[i].lm << " " << b[i].rm << "\n"; // int l = 0, r = 0; // while(q --) { // l = read(); r = read(); // if(r - l + 1 == 1 || r - l + 1 == 2) { printf("Y\n"); continue; } // int ll = 1, lr = cnt, ansl = -1; // while(ll <= lr) { // int mid = (ll + lr) >> 1; // if(b[mid].lm <= l) ansl = mid, ll = mid + 1; // else lr = mid - 1; // } // int rl = 1, rr = cnt, ansr = -1; // while(rl <= rr) { // int mid = (rl + rr) >> 1; // if(b[mid].rm >= r) ansr = mid, rr = mid - 1; // else rl = mid + 1; // } //// cout << ansl << " " << ansr << "\n"; // if(ansr + 1 == ansl && b[ansr].lm <= l && b[ansr].rm >= r) printf("Y\n"); // else if(ansl == ansr && ansl != -1) printf("Y\n"); // else printf("N\n"); // } return 0; }

2|0管道(tunnel)

题目描述

输入格式

输出格式

input1

1 7 15 -5 100 -40 10 10 10

output1

115

input2

3 3 -10 4 -10 3 1 -10 6 2 8

output2

28

样例解释

数据范围

tunnel.zip

#include<iostream> using namespace std; #define MAXN 1005 long long read() { long long x = 0; bool f = 0; char ch = getchar(); while(ch < 48 || ch > 57) { if(ch == 45) f = 1; ch = getchar(); } while(ch >= 48 && ch <= 57) { x = (x << 3) + (x << 1) + (ch - 48); ch = getchar(); } return f ? -x : x; } long long n, m, a[MAXN][MAXN], b[MAXN][MAXN], ans = 0; void update() { long long res = 0; for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) if(b[i][j] == 1) { if(b[i][j + 1] == 2 || b[i][j + 1] == 4) res += max(0ll, a[i][j] + a[i][j + 1]); if(b[i + 1][j] == 3 || b[i + 1][j] == 4) res += max(0ll, a[i][j] + a[i + 1][j]); } else if(b[i][j] == 2) { if(b[i][j - 1] == 1 || b[i][j - 1] == 3) res += max(0ll, a[i][j] + a[i][j - 1]); if(b[i + 1][j] == 3 || b[i + 1][j] == 4) res += max(0ll, a[i][j] + a[i + 1][j]); } else if(b[i][j] == 3) { if(b[i][j + 1] == 2 || b[i][j + 1] == 4) res += max(0ll, a[i][j] + a[i][j + 1]); if(b[i - 1][j] == 1 || b[i - 1][j] == 2) res += max(0ll, a[i][j] + a[i - 1][j]); } else if(b[i][j] == 4) { if(b[i][j - 1] == 1 || b[i][j - 1] == 3) res += max(0ll, a[i][j] + a[i][j - 1]); if(b[i - 1][j] == 1 || b[i - 1][j] == 2) res += max(0ll, a[i][j] + a[i - 1][j]); } // if(res / 2 > ans) { // for(int i = 1; i <= n; i ++) { // for(int j = 1; j <= m; j ++) cout << b[i][j] << " "; // cout << "\n"; // } // cout << res / 2 << "\n"; // } ans = max(ans, res / 2); return; } void dfs(long long x, long long y) { // cout << x << " " << y << "\n"; for(int i = 1; i <= 4; i ++) { b[x][y] = i; if(x == n && y == m) update(); else if(y == m) dfs(x + 1, 1); else dfs(x, y + 1); } return; } int main() { freopen("tunnel.in", "r", stdin); freopen("tunnel.out", "w", stdout); n = read(); m = read(); for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) a[i][j] = read(); dfs(1, 1); cout << ans << "\n"; return 0; }
#include<iostream> #include<cmath> using namespace std; #define MAXN 1005 long long read() { long long x = 0; bool f = 0; char ch = getchar(); while(ch < 48 || ch > 57) { if(ch == 45) f = 1; ch = getchar(); } while(ch >= 48 && ch <= 57) { x = (x << 3) + (x << 1) + (ch - 48); ch = getchar(); } return f ? -x : x; } long long n, m, a[MAXN][MAXN], f[MAXN][MAXN][2], g[MAXN][MAXN][2], ans = 0; int main() { freopen("tunnel.in", "r", stdin); freopen("tunnel.out", "w", stdout); n = read(); m = read(); for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) a[i][j] = read(); for(int i = 2; i <= n; i ++) for(int j = 1; j <= m; j ++) f[i][j][0] = max(f[i - 1][j][0], f[i - 1][j][1] + max(0ll, a[i - 1][j] + a[i][j])), f[i][j][1] = max(f[i - 1][j][0], f[i - 1][j][1]); for(int i = 1; i <= n; i ++) for(int j = 2; j <= m; j ++) g[i][j][0] = max(g[i][j - 1][0], g[i][j - 1][1] + max(0ll, a[i][j - 1] + a[i][j])), g[i][j][1] = max(g[i][j - 1][0], g[i][j - 1][1]); for(int i = 1; i <= m; i ++) ans += f[n][i][0]; for(int i = 1; i <= n; i ++) ans += g[i][m][0]; cout << ans << "\n"; return 0; }

3|0序列上的树(tree)

题目描述

输入格式

输出格式

input1

5 1 2 1 2 1

output1

8

input2

9 1 2 1 3 4 3 5 3 1

output2

15

样例解释

数据范围

tree.zip

#include<iostream> using namespace std; #define MAXN 200005 long long read() { long long x = 0; bool f = 0; char ch = getchar(); while(ch < 48 || ch > 57) { if(ch == 45) f = 1; ch = getchar(); } while(ch >= 48 && ch <= 57) { x = (x << 3) + (x << 1) + (ch - 48); ch = getchar(); } return f ? -x : x; } long long n, a[MAXN], ans = 0, cnt = 0, b[MAXN], p[MAXN]; bool c[MAXN]; int main() { freopen("tree.in", "r", stdin); freopen("tree.out", "w", stdout); n = read(); for(int i = 1; i <= n; i ++) a[i] = read(); for(int i = 1; i <= n; i ++) { b[++ cnt] = a[i]; if(b[cnt] == b[cnt - 2] && !c[b[cnt - 1]]) c[b[cnt - 1]] = true, cnt -= 2; } if(cnt == 1) { for(int i = 1; i <= n; i ++) p[a[i]] ++; for(int i = 1; i <= n; i ++) ans += (p[i] - 1) * p[i] / 2; cout << ans + n << "\n"; return 0; } for(int l = 1; l < n - 1; l ++) for(int r = l + 2; r <= n; r ++) { if(a[l] != a[r]) continue; cnt = 0; for(int i = l; i <= r; i ++) c[a[i]] = false; for(int i = l; i <= r; i ++) { b[++ cnt] = a[i]; if(b[cnt] == b[cnt - 2] && !c[b[cnt - 1]]) c[b[cnt - 1]] = true, cnt -= 2; } if(cnt == 1) ans ++; } cout << ans + n << "\n"; return 0; }

4|0生存(survive)

题目描述

输入格式

输出格式

input1

3 2 1 2 3 1 2 2 3 1 2 2 1 2

output1

5

样例解释

数据范围

survive.zip

#include<iostream> #include<vector> using namespace std; #define MAXN 1000005 long long read() { long long x = 0; bool f = 0; char ch = getchar(); while(ch < 48 || ch > 57) { if(ch == 45) f = 1; ch = getchar(); } while(ch >= 48 && ch <= 57) { x = (x << 3) + (x << 1) + (ch - 48); ch = getchar(); } return f ? -x : x; } long long n, m, a[MAXN], ans = 0; int main() { freopen("survive.in", "r", stdin); freopen("survive.out", "w", stdout); n = read(); m = read(); for(int i = 1; i <= n; i ++) a[i] = read(); for(int i = 1; i <= n; i ++) ans += a[i]; cout << ans << "\n"; return 0; }

100+35+50+0=185


__EOF__

本文作者So_noSlack
本文链接https://www.cnblogs.com/So-noSlack/p/18338616.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   So_noSlack  阅读(22)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
历史上的今天:
2023-08-02 CF1468N 题解
2023-08-02 CF479C 题解
2023-08-02 CF1282A 题解
2023-08-02 CF1363A 题解
2023-08-02 CF1359A 题解
2023-08-02 第二节 基础算法 - 2
2023-08-02 第一节 基础算法 - 1
点击右上角即可分享
微信分享提示