2020CSP-J2比赛记录题解

题目请看洛谷

备注:这次比赛我是没打的


T1

先把数转成二进制,逐位计算,并判断是否可完整正确拆分

贴一下代码
#include <bits/stdc++.h>
using namespace std;
#define fre(c) freopen(c".in","r",stdin);freopen(c".out","w",stdout);
#define ll long long
#define endl "\n"
#define ios ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define cst const
cst ll N = 1e3 + 5;
ll n, a[N], cnt, now = 1;
ll read() {char c;ll sum = 0, f = 1;c = getchar();while (!isdigit(c)) {if (c == '-')f *= -1;c = getchar();}while (isdigit(c)) {sum = sum * 10 + (c - '0');c = getchar();}return sum * f;
}
int main() {
//	ios
//	fre("")n = read();if (n % 2 == 1) {cout << -1;return 0;}now = 1;while (now <= n) now *= 2;while (n > 0) {	if (now <= n) {	a[cnt ++] = now; n -= now; } now /= 2; }for (int i = 0; i < cnt; i ++) { if (i > 0) {cout << " ";} cout << a[i]; }return 0;
}

赛时:-point

赛后:100point


T2

以前看过思路

用个桶存,无脑sort也可以拿分,存储分数线低的位置,听说还可以用对顶堆

贴一下代码
#include <bits/stdc++.h>
using namespace std;
#define fre(c) freopen(c".in","r",stdin);freopen(c".out","w",stdout);
#define ll long long
#define endl "\n"
#define ios ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define cst const
cst ll N = 1e3 + 5;
ll n, w, x, a[N], sum;
ll read() {char c;ll sum = 0, f = 1;c = getchar();while (!isdigit(c)) {if (c == '-')f *= -1;c = getchar();}while (isdigit(c)) {sum = sum * 10 + (c - '0');c = getchar();}return sum * f;
}
int main() {
//	ios
//	fre("")n = read();w = read();for (ll i = 1; i <= n; i ++) {x = read();a[x] ++;sum = 0;for (ll j = 600; j >= 0; j --) {sum += a[j];if (sum >= max(1LL, i * w / 100)) {cout << j << " ";break ;}}}return 0;
}

赛时:-point

赛后:100point


T3

先用转成栈,接着变成树形结构

贴一下标程
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 1000005;char s[N];
int a[N];
int son[N][2], ck;
int flag[N], c[N];
int n, q;
int dfs(int u, int g) {a[u] ^= g;if (u <= n) {return a[u];}int x = dfs(son[u][0], g ^ flag[son[u][0]]);int y = dfs(son[u][1], g ^ flag[son[u][1]]);if (a[u] == 2) {if (x == 0) c[son[u][1]] = 1;if (y == 0) c[son[u][0]] = 1;return x & y;} else {if (x == 1) c[son[u][1]] = 1;if (y == 1) c[son[u][0]] = 1;return x | y;}
}
void dfs2(int u) {if (u <= n) return;c[son[u][0]] |= c[u];c[son[u][1]] |= c[u];dfs2(son[u][0]);dfs2(son[u][1]);
}
int main() {// freopen("expr.in", "r", stdin);// freopen("expr.out", "w", stdout);gets(s);scanf("%d", &n);ck = n;for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);}stack<int> b;for (int i = 0; s[i]; i += 2) {if (s[i] == 'x') {int x = 0;i++;while (s[i] != ' ') {x = x * 10 + s[i] - '0';i++;}i--;b.push(x);} else if (s[i] == '&') {int x = b.top();b.pop();int y = b.top();b.pop();b.push(++ck);a[ck] = 2;son[ck][0] = x;son[ck][1] = y;} else if (s[i] == '|') {int x = b.top();b.pop();int y = b.top();b.pop();b.push(++ck);a[ck] = 3;son[ck][0] = x;son[ck][1] = y;} else if(s[i] == '!'){flag[b.top()] ^= 1;}}int ans = dfs(ck, flag[ck]);dfs2(ck);scanf("%d", &q);while (q--) {int x;scanf("%d", &x);printf("%d\n", c[x] ? ans : !ans);}return 0;
}

赛时:-point

赛后:-point

T4

记忆化搜索,分析来时路

贴一下代码
#include <bits/stdc++.h>
using namespace std;
#define fre(c) freopen(c".in","r",stdin);freopen(c".out","w",stdout);
#define ll long long
#define endl "\n"
#define ios ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define cst const
cst ll N = 1e3 + 5;
ll n, m, a[N][N], dp[N][N];
inline ll read() {char c;ll sum = 0, f = 1;c = getchar();while (!isdigit(c)) {if (c == '-')f *= -1;c = getchar();}while (isdigit(c)) {sum = sum * 10 + (c - '0');c = getchar();}return sum * f;
}
int main() {
//	ios
//	#ifdef debug
//		fre("D")
//	#endifn = read();m = read();for (ll i = 1; i <= n; i ++) {for (ll j = 1; j <= m; j ++) {a[i][j] = read();}}for (ll i = 1; i <= n; i ++) {dp[i][1] = dp[i - 1][1] + a[i][1];}for (ll j = 2; j <= m; j ++) {vector<ll> left(n + 2), right(n + 2);left[1] = dp[1][j - 1] + a[1][j];for (ll i = 2; i <= n; i ++) {left[i] = max(left[i - 1], dp[i][j - 1]) + a[i][j];}right[n] = dp[n][j - 1] + a[n][j];for (ll i = n - 1; i >= 1; i --) {right[i] = max(right[i + 1], dp[i][j - 1]) + a[i][j];}for (ll i = 1; i <= n; i ++) {dp[i][j] = max(left[i], right[i]);}}cout << dp[n][m];return 0;
}

赛时:-point

赛后:100point


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/934743.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Binder.getCallingPid()和Binder.getCallingUid()漏洞分析

最近在学习安卓漏挖,在分析ghera数据集时发现一个很有意思的binder特性,但还没搞懂底层原理,先挖个坑 漏洞分析EnforceCallingOrSelfPermission-PrivilegeEscalation-Lean以下代码使用Binder.getCallingPid()和Bind…

详细介绍:golang基础语法(五)切片

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

让博客园设置支持PlantUml画图

1. 引入 2. 博客园不支持plantuml渲染 3. 编写js脚本支持plantuml 4. 缺点‍ 1. 引入众所周知,我们在写博客的时候,常使用PlantUML 和 Mermaid绘制图表、流程图、架构图。这是因为用代码去画图,不怎么需要手动控制格…

jj

jjimport numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from sklearn.preprocessing import StandardScaler from sklearn.decomposition import PCA from sklearn.cluste…

光谱相机的未来趋势 - 详解

光谱相机的未来趋势 - 详解pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", …

Hall定理学习笔记

内容 设二分图左部点点数为 \(x\),右部点点数为 \(y\),且满足 \(x<y\)。定义一张二分图的完备匹配为:对于任意一个左部点都有与之匹配的右部点。 \(\text{Hall}\) 定理的内容是:一张二分图有完备匹配,等价于对…

面向对象抽象,接口多态综合-动物模拟系统

1、抽象一个动物类,会说话和走路。 public abstract class Animal() { public abstract void Speak(); public abstract void Walk(); } 2、抽象出能力,有的动物会飞,有的动物能用四条腿走路 interface IFly { void…

实用指南:APache shiro-550 CVE-2016-4437复现

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

Spark - deprecated registerTempTable() function

Spark - deprecated registerTempTable() functionIn Apache Spark, the function registerTempTable() was an old API (deprecated since Spark 2.0 and removed in Spark 3.0) that allowed you to register a Data…

MinGW-即时入门-全-

MinGW 即时入门(全)原文:zh.annas-archive.org/md5/a899d9a6a04025b2abd50163c83cff2a 译者:飞龙 协议:CC BY-NC-SA 4.0第一章. 立即开始使用 MinGW 欢迎使用 立即开始使用 MinGW。 本书特别创建,旨在为您提供所…

个人微信开发文档

个人微信开发文档、微信个人号api开发、微信机器人API 微信机器人是一种基于微信平台的自动化程序,能够根据用户的输入自动回复信息。它可以用于客服、信息查询、娱乐等多个场景。通过程序化的方式,微信机器人可以在…

Splay学习笔记

问题分析: (来源:洛谷P3369【模板】普通平衡树) 您需要动态地维护一个可重集合 \(M\),并且提供以下操作:向 \(M\) 中插入一个数 \(x\)。 从 \(M\) 中删除一个数 \(x\)(若有多个相同的数,应只删除一个)。 查询…

象棋图片转FEN字符串详细教程

如把下图转换成:3ak4/7R1/3aCcN2/p7p/6r2/9/Pr1p1n2P/4B1p2/9/2BAKA1R1 模型21K,Intel N100上训练时间0.969秒,识别时间0.957秒。识别率好像是100% 一、安装软件包 apt install python3-scipy python3-pil 二、建目…

自然语言处理在风险识别中的应用

本文介绍了如何利用自然语言处理和机器学习技术来识别和预测风险,包括在在线教育平台和产品开发阶段的应用,以及相关技术架构和团队构成。利用自然语言处理理解和识别风险 作为某中心的应用科学经理,Muthu Chandras…

详细介绍:正点原子【第四期】Linux之驱动开发学习笔记-6.1 pinctrl和gpio子系统

详细介绍:正点原子【第四期】Linux之驱动开发学习笔记-6.1 pinctrl和gpio子系统pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-…

cat

基本概述 cat命令来自英文词组”concatenate files and print“的缩写,其功能是用于在终端设备上显示文件内容。在Linux系统中有很多用于查看文件内容的命令,例如more、tail、head等,每个命令都有各自的特点。cat命…

深入解析:可持续金融的新范式:拆解欧盟ESG监管体系及其全球影响力

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

Docker和K8S的区别详解 - 指南

Docker和K8S的区别详解 - 指南2025-10-11 12:39 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !importan…

qt everywhere souce code编译 - 实践

qt everywhere souce code编译 - 实践pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Mona…

2023 CCPC final G

G. China Convex Polygon Contest 反悔贪心。 首先可以考虑对 \(b\) 排序,显然思考越快的题可以使手里攒着的题更多更有选择的空间。 如果正着贪心的话就是,当前能做就立马提交,如果当前的时间更优但选不了就从之前…