PTA 520钻石争霸赛 2021
7-1 自动编程
签到题
#include<bits/stdc++.h> typedef long long ll;
const int maxm = 1e5 + 5;
const int infmax = INT_MAX;
const int infmin = INT_MIN;
using namespace std; int main() {
int n;
cin >> n;
printf("print(%d)", n);
return 0;
}
7-2 加油冲鸭
签到
#include<bits/stdc++.h> typedef long long ll;
const int maxm = 1e5 + 5;
const int infmax = INT_MAX;
const int infmin = INT_MIN;
using namespace std; int main() {
int n, m, s;
cin >> n >> m >> s;
int p = n - m * s;
if (p > n / 2) {
printf("hai sheng %d mi! jia you ya!\n", p);
} else {
printf("hai sheng %d mi! chong ya!\n", p);
}
return 0;
}
7-3 520的表白
签到
#include<bits/stdc++.h> typedef long long ll;
const int maxm = 1e5 + 5;
const int infmax = INT_MAX;
const int infmin = INT_MIN;
using namespace std; int main() {
int n;
cin >> n;
for (int i = 0; i < 520; i++)
cout << n << "\n";
return 0;
}
7-4 奇葩楼层
遍历一遍楼层,带忌讳的数字不记数就行
#include<bits/stdc++.h> typedef long long ll;
const int maxm = 1e5 + 5;
const int infmax = INT_MAX;
const int infmin = INT_MIN;
using namespace std; int main() {
int n, m;
cin >> n >> m;
int sum = 0;
for (int i = 1; i <= n; i++) {
int j = i, f = 1;
while (j) {
int k = j % 10;
j /= 10;
if (k == m) {
f = 0;
break;
}
}
if (f) sum++;
}
cout << sum << "\n";
return 0;
}
7-5 大勾股定理
平方和数太大,找规律,可以发现n = 1时,3开始;n = 2时,10开始, n = 3时,21开始。
1 * 3 = 3;
2 * 5 = 10;
3 * 7 = 21;
从而猜出n * (2 * n + 1)。
15分题不会搞很复杂的数列的。
#include<bits/stdc++.h> typedef long long ll;
const int maxm = 1e5 + 5;
const int infmax = INT_MAX;
const int infmin = INT_MIN;
using namespace std; int main() {
int n;
cin >> n;
int k = n * (2 * n + 1);
for (int i = k; i <= k + n; i++) {
if (i == k) cout << i << "^2";
else cout << " + " << i << "^2";
}
cout << " =\n";
int j = k + n + 1, m = 0;
while (m < n) {
if (m == 0) cout << j << "^2";
else cout << " + " << j << "^2";
j++;
m++;
}
return 0;
}
7-6 矩阵列平移
模拟,注意写的时候不要把行和列写岔了就没啥问题
#include<bits/stdc++.h> typedef long long ll;
const int maxm = 1e5 + 5;
const int infmax = INT_MAX;
const int infmin = INT_MIN;
using namespace std; int a[110][110]; int main() {
int n, k, x;
cin >> n >> k >> x;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> a[i][j];
int m = 1;
for (int i = 2; i <= n; i += 2) {
for (int j = n; j > m; j--)
a[j][i] = a[j - m][i];
for (int j = 1; j <= m; j++)
a[j][i] = x;
m++;
if (m > k) m = 1;
} for (int i = 1; i <= n; i++) {
int sum = 0, j = 1;
while (j <= n) sum += a[i][j], j++;
if (i == 1)
cout << sum;
else cout << ' ' << sum;
}
return 0;
}
7-7 约会大作战
题解在代码理,时间紧代码写的很不好,巨巨可以用结构体整理以下
#include<bits/stdc++.h> typedef long long ll;
const int maxm = 1e5 + 5;
const int infmax = INT_MAX;
const int infmin = INT_MIN;
using namespace std; int a[110][110], b[110][110], su1[110], su2[110];
int st1[110], st2[110], max1[110], max2[110];
int pre1[110], pre12[110];
int pre2[110], pre22[110]; int main() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < 110; i++) {
max1[i] = max2[i] = -110;//存该组第i位前2的最大好感度,初始化写最小
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++)
cin >> a[i][j];//1组第i位对2组第j位的好感度
} for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++)
cin >> b[i][j];//2组第i位对1组第j位的好感度
} int x, y, f = 0;
while (q--) {
cin >> x >> y;
st1[x]++;
st2[y]++;//判断是否拒绝2次
if (st1[x] > 2 && st2[y] > 2) {//都已经拒绝2次
if (a[x][y] > max1[x] && b[y][x] > max2[y]) {//判断是否大于拒绝前2次人的好感度
if (!su1[x] && !su2[y]) {//su是表示有木有约会成功过,1就是约过了
su1[x] = su2[y] = 1;
cout << x << ' ' << y << "\n";
f = 1;//判断有木有人约会成功过
}
}
} pre1[x] = pre12[x];
pre12[x] = a[x][y];
//1组第x个人的拒绝的前2个的好感度,这个时候有新的好感度,所以把第2个好感度
//覆盖到第一个,第二个好感度等于新的拒绝的好感度 pre2[y] = pre22[y];//与上同理
pre22[y] = b[y][x]; max1[x] = max(pre1[x], pre12[x]);//存该组第x位拒绝前2位的最大好感度
max2[y] = max(pre2[y], pre22[y]);//同理
}
if (!f) cout << "PTA is my only love\n";//没有人约会
return 0;
}
7-8 浪漫侧影
左右视其实就是二叉树各层数的第一个和最后一个,所以根据中后序遍历下前序,声明个层数向量存每层的树节点就行,最后根据左右视输出每层的第一个和最后一个节点
#include<bits/stdc++.h> typedef long long ll;
const int maxm = 1e5 + 5;
const int infmax = INT_MAX;
const int infmin = INT_MIN;
using namespace std; int in[250], post[250], maxdepth = 0;
vector<int> v[250]; void pre(int root, int start, int end, int depth) {
if (start > end)
return;
maxdepth = max(maxdepth, depth);
int i = start;
while (i < end && in[i] != post[root]) i++;
v[depth].push_back(post[root]);
pre(root - 1 - (end - i), start, i - 1, depth + 1);
pre(root - 1, i + 1, end, depth + 1);
} int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> in[i];
for (int i = 1; i <= n; i++) cin >> post[i]; pre(n, 1, n, 1);
cout << "R:";
for (int i = 1; i <= maxdepth; i++) cout << ' ' << v[i].back();
cout << "\n"; cout << "L:";
for (int i = 1; i <= maxdepth; i++) cout << ' ' << v[i].front();
cout << "\n";
return 0;
}
over,代码写的有点烂,巨巨们轻喷。
PTA 520钻石争霸赛 2021的更多相关文章
- PTA2022 520钻石争霸赛题解
		
7-1 520表白 不用说 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int max ...
 - PAT520 钻石争霸赛 7-6 随机输一次
		
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1000; ll n ...
 - codevs 2021 中庸之道
		
2021 中庸之道 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 给定一个长度为N的序列,有Q次询问,每次 ...
 - AC日记——中庸之道 codevs 2021
		
2021 中庸之道 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 给定一个长度为N的序列 ...
 - 皓远的第二次博客作业(最新pta集,链表练习及期中考试总结)
		
前言: 知识点运用:正则表达式,有关图形设计计算的表达式和算法,链表的相关知识,Java类的基础运用,继承.容器与多态. 题量:相较于上次作业,这几周在java方面的练习花了更多的精力和时间,所要完成 ...
 - 深入super,看Python如何解决钻石继承难题 【转】
		
原文地址 http://www.cnblogs.com/testview/p/4651198.html 1. Python的继承以及调用父类成员 python子类调用父类成员有2种方法,分别是普通 ...
 - 1Z0-053 争议题目解析520
		
1Z0-053 争议题目解析520 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 520.Which of the following are not disabled by de ...
 - 干货分享:MySQL之化险为夷的【钻石】抢购风暴
		
抢购钻石不稀奇,稀奇的是有钱赚不到,事情发生在2015年5月20日,大好的日子自然少不了商家的参与.即可为您还原现场,解决思路献给各位,请欣赏Show Time,everybody~ 1.优化起因及工 ...
 - lumia 520无法开机
		
拿出尘封已久的lumia 520,发现其开机困难,现象如下: 1.拿掉电池再放回去有几率开机 2.轻轻地用手机砸向桌面时手机会重启 因为手机在更新WP8.1之后就出问题了,所以先得定位问题,在黑屏的时 ...
 
随机推荐
- 西文字符与中文GBK编码的区别
			
一般来讲二者读取的时候西文字符的数值是正,而中文字符的数值是负的,此时读取的是中文字符的前一半,需要再读取一个char类型的数据,在大多数运行环境下这个规则都是用. ps:转自算法竞赛的笔记,要注意在 ...
 - jsx/tsx使用cssModule和typescript-plugin-css-modules
			
目录 1,前言 2,效果图 3,如何使用 3.1,安装 3.2,配置 4,示例 5,插件错误处理 5.1,错误触发原因 5.2,解决办法 1,前言 在vite/webpack搭建的项目中,不管是vue ...
 - 第十天python3 函数的销毁
			
全局函数销毁 三种方式: 1.重新定义同名函数 2.del语句删除函数对象 3.程序结束时 局部函数销毁 三种方式: 1.重新在上级作用域定义同名函数: 2.del语句删除函数对象: 3.上级作用域销 ...
 - Junit使用步骤和junit_@Before&@After
			
测试: 1.定义一个测试类(测试用例) 建议: 测试类名:被测试的类型Test CalculatorTest 包名:xxx.xxx.xx.test com.li.Test 2.定义测试方法:可以独立运 ...
 - python 操作json数据
			
简介 JSON(JavaScript Object Notation, JS对象简谱)是一种轻量级的数据交换格式,通常是以键值对的方式呈现,其简洁和清晰的层次结构使得JSON成为理想的数据交换语言,而 ...
 - 使用centos linux vps搭建jupyter notebook踩坑日记
			
今天我尝试用vps搭建在线jupyter notebook网站时遇到了这样一个问题: [W 21:48:07.243 NotebookApp] SSL Error on 9 ('171.115.101 ...
 - es6中的Proxy和vue中的数据代理的异同
			
1:概述 1-1:Proxy 用于修改某些操作的默认行为,Proxy可以说在对对象进行各种访问或者操作的时候在外层进行一层拦截,在操作之前都需要经过这种拦截.proxy返回的是一个新对象,可以通过操作 ...
 - 一文带你弄懂 JVM 三色标记算法!
			
大家好,我是树哥. 最近和一个朋友聊天,他问了我 JVM 的三色标记算法.我脑袋一愣发现竟然完全不知道!于是我带着疑问去网上看了几天的资料,终于搞清楚啥事三色标记算法,它是用来干嘛的,以及它和 CMS ...
 - 通俗理解ABP中的模块Module
			
网上有不少文章说ABP的模块,有的直接翻译自官网介绍,有的分析Modlue的源代码,有的写一通代码,没什么注释,很少有能通俗说清的.那么,有两个问题:1.ABP中的模块到底是什么?2.搞这个东西是干嘛 ...
 - Mybatis简单入门--插入数据
			
1. 开发环境 IDE:IDEA 构建工具:maven4.0.0 MySQL版本:8.0.11. 记得创建好数据库 Mybatis版本:3.5.7 MySQL不同版本的注意事项 驱动类driver-c ...