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. 牛客编程巅峰赛S2第7场 - 钻石&王者 A.牛牛的独特子序列 (字符串,二分)

    题意:给你一个字符串,找出一个类似为\(aaabbbccc\)这样的由连续的\(abc\)构成的子序列,其中\(|a|=|b|=|c|\),问字符串中能构造出的子序列的最大长度. 题解:这题刚开始一直 ...

  2. Codeforces Global Round 11 C. The Hard Work of Paparazzi (DP)

    题意:有\(r\)X\(r\)的网格图,有\(n\)位名人,会在\(t_i\)时出现在\((x_i,y_i)\),如果过了\(t_i\)名人就会消失,从某一点走到另外一点需要花费的时间是它们之间的曼哈 ...

  3. - Visible Trees HDU - 2841 容斥原理

    题意: 给你一个n*m的矩形,在1到m行,和1到n列上都有一棵树,问你站在(0,0)位置能看到多少棵树 题解: 用(x,y)表示某棵树的位置,那么只要x与y互质,那么这棵树就能被看到.不互质的话说明前 ...

  4. 二叉排序树的构造 && 二叉树的先序、中序、后序遍历 && 树的括号表示规则

    二叉排序树的中序遍历就是按照关键字的从小到大顺序输出(先序和后序可没有这个顺序) 一.以序列 6 8 5 7 9 3构建二叉排序树: 二叉排序树就是中序遍历之后是有序的: 构造二叉排序树步骤如下: 插 ...

  5. 7.PowerShell DSC之模式

    DSC两种模式 DSC有两种模式,Push模式和Pull模式 Push模式 基本流程 写配置--编译生成mof--推送到目标服务器,由目标服务器LCM执行mof并进行指定的配置 优点 架构简单.成本低 ...

  6. Kubernets二进制安装(19)之集群平滑升级

    在实际生产环境中,部署好的集群稳定就行了,但是,如果需要使用到新的功能或当前版本出现了严重的漏洞,都建议做升级,本教程是将node节点从v1.15.10版本平滑升级到v1.15.12版本,如果升级到相 ...

  7. Rsyncd 同步服务

    目录 数据备份的策略 三种数据备份 三种数据备份的比较(转载) 不同数据备份类型组合说明(转载) Rsyncd 服务传输模式(remote synchronizetion deamon) 本地传输模式 ...

  8. ansible的Ad-hoc命令

    本文主要介绍了ansible的Ad-hoc命令. Ansible提供两种方式去完成任务,一是 ad-hoc 命令,一是写 Ansible playbook.前者可以解决一些简单的任务, 后者解决较复杂 ...

  9. HDU 3681 Prison Break(状压DP + BFS)题解

    题意:一张图,F是起点,Y是必须要到的点,D不能走,G可以充电.可以往四个方向走,每走一步花费一个电,走到G可以选择充满电或者不充,每个G只能充一次.问你走遍Y的最小初始点亮.number(G) + ...

  10. js location API All In One

    js location API All In One location "use strict"; /** * * @author xgqfrms * @license MIT * ...