当前位置: 首页 > news >正文

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.zskr.cn/news/18750.html

相关文章:

  • 让博客园设置支持PlantUml画图
  • 光谱相机的未来趋势 - 详解
  • Hall定理学习笔记
  • 面向对象抽象,接口多态综合-动物模拟系统
  • 个人微信开发文档
  • 象棋图片转FEN字符串详细教程
  • 详细介绍:正点原子【第四期】Linux之驱动开发学习笔记-6.1 pinctrl和gpio子系统
  • 深入解析:可持续金融的新范式:拆解欧盟ESG监管体系及其全球影响力
  • 2023 CCPC final G
  • 八字手链人物传记计划——旭
  • 详细介绍:c# datagridview添加list内容
  • MATLAB复杂曲线曲面造型及导函数实现
  • 达梦使用jemalloc内存分配器
  • 基于Python的FastAPI后端开发框架如何使用PyInstaller 进行打包与部署
  • 2025 年气体/实验室/调压/气路/减压阀厂家推荐榜:聚焦安全与专业,助力各行业精准选品
  • 摸鱼混子回归 - ZERO
  • 2025 年国内润滑油厂商最新推荐榜:聚焦优质品牌实力,助力企业精准选品润滑油净化/过滤/回用/液压油润滑油过滤厂商推荐
  • 基于形态学的权重自适应图像去噪的MATLAB实现
  • 2025 年油水分离器 / 气液分离器 / 液固分离器 / 水分离器 / 油分离器厂家推荐:西安同大技术沉淀与流体净化解决方案解析
  • OOP-实验1
  • 哪款剪贴板增强软件最好用?有什么剪贴板内容大全值得分享?多款剪切板历史免费版管理工具推荐
  • EndNote文献管理工具!研究生必备软件!超详细下载安装教程(附下载地址)
  • 鸿蒙应用开发从入门到实战(十九):样式复用案例
  • 2025 年最新推荐冰醋酸厂商综合实力排行榜: 厂商定制服务与仓储能力深度解析昆山/太仓/吴江区/吴中区/相城区/姑苏区冰醋酸厂商推荐
  • 中电金信:“源启大模型文本生成算法”成功通过互联网信息服务算法备案
  • 2025 年冷热冲击试验箱生产厂家最新推荐榜:聚焦三箱 / 两箱 / 吊篮式 / 小型 / 风冷式 / 可程式设备,精选优质企业助力高效选购
  • 批量文件重命名工具(带撤销功能)
  • Trae与Gitee MCP强强联合:AI编程生态迎来重大升级
  • 1_数组
  • 创建数字遗嘱:为亲人留下数字足迹指南