1.简单数学

1008 Elevator (20分)

模拟题

#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <cmath>
#define ll long long
#define inf 0x3f3f3f
using namespace std;
const int maxn = 1e4+100;
int n, sum, now, tmp;
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf("%d", &tmp);
int num = tmp-now;
sum += num > 0 ? num*6 : num*(-4);
now = tmp;
}
sum += 5*n;
printf("%d", sum);
}

1049 Counting Ones (30 分)

1的个数等于各个位出现1的次数的累加和,因此我们计算各个位上对答案的贡献即可。

那么关键的问题就在如何计算某一位上的贡献,当然就是求这一位为1时数的个数,如下:

(具体为什么是这样可以在脑子或者纸上演算一下)

我一开始的思路是对的,但是那会想不出来具体的做法,考试时暴力骗个分还是可以的。另外上机指南中提到可以对程序进行边界测试,确实应当如此,以后多使用几种方法来测试自己的代码

#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define ll long long
#define inf 0x3f3f3f3f
#define pb push_back
#define pii pair<int,int>
using namespace std;
const int maxn = 2e6+100;
int n, res;
int main(){
scanf("%d", &n);
int left = n, right, a = 1, now;
while(left){
now = left%10, right = n-left*a, left /= 10;
if(now==0) res += left*a;
else if(now==1) res += left*a+right+1;
else res += (left+1)*a;
a *= 10;
}
printf("%d", res);
}

Reference:

https://blog.csdn.net/CV_Jason/article/details/85112495

1069 The Black Hole of Numbers (20 分)

按照题目要求模拟即可,不过要注意要考虑全面:

1.所有输出都要求4位数

2.考虑特殊样例如6174、2222、1情况下的处理。如输入为1的时候要补充前导0;输入为6174的时候要输出一行而不能直接退出

#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define ll long long
#define inf 0x3f3f3f3f
#define pb push_back
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+100;
string a, b, c, last, s;
int tmp;
int main(){
cin >> c;
while(1){
for(int i = 0; i < 4-c.length(); i++) s += "0";
s += c, a = b = s, last = c;
sort(a.begin(), a.end()), sort(b.rbegin(), b.rend());
c = to_string(stoi(b) - stoi(a)), s.clear();
printf("%04d - %04d = %04d\n", stoi(b), stoi(a), stoi(c));
if(c=="6174"||c=="0") break;
}
}

PTA甲级—数学的更多相关文章

  1. PTA甲级1094 The Largest Generation (25分)

    PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...

  2. PTA甲级B1061 Dating

    目录 B1061 Dating (20分) 题目原文 Input Specification: Output Specification: Sample Input: Sample Output: 生 ...

  3. PTA 甲级 1139

    https://pintia.cn/problem-sets/994805342720868352/problems/994805344776077312 其实这道题目不难,但是有很多坑点! 首先数据 ...

  4. PTA甲级—链表

    1032 Sharing (25分) 回顾了下链表的基本使用,这题就是判断两个链表是否有交叉点. 我最开始的做法就是用cnt[]记录每个节点的入度,发现入度为2的节点即为答案.后来发现这里忽略了两个链 ...

  5. PTA甲级—STL使用

    1051 Pop Sequence (25分) [stack] 简答的栈模拟题,只要把过程想清楚就能做出来. 扫描到某个元素时候,假如比栈顶元素还大,说明包括其本身的在内的数字都应该入栈.将栈顶元素和 ...

  6. PTA甲级—常用技巧与算法

    散列 1078 Hashing (25 分) Quadratic probing (with positive increments only) is used to solve the collis ...

  7. PTA L3-023 计算图 (dfs+数学推导)

    “计算图”(computational graph)是现代深度学习系统的基础执行引擎,提供了一种表示任意数学表达式的方法,例如用有向无环图表示的神经网络. 图中的节点表示基本操作或输入变量,边表示节点 ...

  8. PAT甲级——1104 Sum of Number Segments (数学规律、自动转型)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90486252 1104 Sum of Number Segmen ...

  9. (数学) PTA 1005 继续(3n+1)猜想 (25 分)

    1005 继续(3n+1)猜想 (25 分) 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程 ...

随机推荐

  1. .net core面试题

    第1题,什么是ASP net core? 首先ASP net core不是 asp net的升级版本.它遵循了dot net的标准架构, 可以运行于多个操作系统上.它更快,更容易配置,更加模块化,可扩 ...

  2. PowerShell随笔3 ---别名

    上一篇提到了别名,这个有必要说一下,因为我们常常会遇到以下两种情况: 自己写脚本,想快速一些,使用命名 看别人的脚本,发现别人和你想的一样,用了别名,但是你忘记了这个别名是什么意思. 我们可以通过Ge ...

  3. Interop.Word Documents.Open is null

    问题描述 程序在Windows Server 2012 R2调用Word组件正常,但是换到Windows Server 2008 R2之后,程序异常. 代码 Microsoft.Office.Inte ...

  4. windows创建p12格式的ios开发证书的流程

    现在做ios开发,原生的开发已经不是第一选择,现在有很多不同的H5开发框架,在性能上都不输原生开发,而UI方便却能做得比原生更炫,比如CSS得灵活度肯定是比原生开发出来得应用更灵活的. 我们在开发IO ...

  5. 实战交付一套dubbo微服务到k8s集群(5)之使用Jenkins进行持续构建交付dubo服务的提供者

    1.登录到jenkins,新建一个项目 2.新建流水线 3.设置保留的天数及份数 4.添加第一个参数:设置项目的名称 5.添加第二个参数:docker镜像名称 6.添加第三个参数:项目所在的git中央 ...

  6. Zabbix 配置监控 & 触发器

    Zabbix 自定义监控 zabbix-agent 获取数据,然后定义,交给 zabbix-server 端 Zabbix 配置监控项 监控的内容 # 监控服务器登录用户的数量 [root@web01 ...

  7. Harbor 镜像仓库搭建

    安装 Docker # 下载 Docker 二进制包 [root@k8s-master01 ~]# wget https://download.docker.com/linux/static/stab ...

  8. Kubernets二进制安装(7)之部署主控节点服务--apiserver简介

    API Server简介 Kubernetes API Server提供了K8S各类资源对象(如:pod.RC.Service等)的增删改查及watch等HTTP Rest接口,是整个系统的数据总线和 ...

  9. LVS+Keepalived深度理解,阐述你不知道的坑点

    1. LVS简介 1. 什么是LVS? LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内 ...

  10. vue-cli-service & @vue/cli-service

    vue-cli-service & @vue/cli-service https://www.npmjs.com/package/@vue/cli-service https://yarnpk ...