![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
模板题
MokylinJay
Hello World!
展开
-
快速幂
1. 递归写法的快速幂给定三个正整数a、b、m(a < 109,b < 1018,1 < m < 109)求ab%m快速幂基于以下事实:如果b是奇数,那么有ab = a * ab-1如果b是偶数,那么有ab = ab/2 * ab/2显然b为奇数的情况总是可以转换为b为偶数的情况,而b为偶数的情况又可以进一步转换为b/2的情况。经过log(b)级别的转换后,就可以把b变为0,而任何数的0次幂都为1。快速幂的递归写法,代码如下:#include <iost原创 2020-11-16 15:57:15 · 73 阅读 · 0 评论 -
区间贪心
区间不相交问题描述:给出N个开区间(x,y),从中选择尽可能多的开区间,使得这些开区间两两之间没有交集。步骤:将所有区间按照左端点从大到小进行排序左端点相等,则按照右端点从小到大进行排序总是选择左端点最大的区间(若左端点相等,则选择右端点最小的区间)思路:首先我们明确一点,当区间a被区间b包含时,我们一定会选择区间a,在这点的基础上我们看一个例子。例子:如图为排序后的一般情况(从上到下依次命名为I1~I5)现在我们去掉区间包含的情况I2,I3(因为我们一定不会选他们,不妨忽视掉)原创 2020-10-29 16:07:05 · 77 阅读 · 0 评论 -
1020 月饼(简单贪心)
题目链接#include <iostream>#include <stdio.h>#include <algorithm>#include <math.h>#include <string.h>#include <queue>using namespace std;struct mooncake // 定义mooncake结构体,方便排序{ double store; double totalPri原创 2020-10-27 21:30:01 · 117 阅读 · 0 评论 -
递归
1. 计算阶乘#include <iostream>#include <stdio.h>#include <algorithm>#include <math.h>#include <string.h>#include <queue>using namespace std;int f(int n) // 递归计算阶乘{ if (n == 0) { return 1; }原创 2020-10-27 17:42:06 · 105 阅读 · 0 评论 -
散列
1. 输入N个数,进行M次查询,输出所查询的数是否在N个数中出现#include <iostream>#include <cstdio>#include <cstring>#include <stdio.h>#include <algorithm>using namespace std;const int maxn = 100010;bool hashTable[maxn] = {false}; // 值为true代表该数出现过原创 2020-10-25 18:25:10 · 88 阅读 · 0 评论 -
1025 PAT Ranking(结构体排序)
题目链接思路:1. 分考场读入考生数据2. 对每个考场的考生进行排序,并对local_rank进行赋值3. 对全部考生进行排序,以变量r记录考生名次#include <iostream>#include <cstdio>#include <cstring>#include <stdio.h>#include <algorithm>using namespace std;struct Student{ char原创 2020-10-25 17:28:39 · 77 阅读 · 0 评论 -
问题 I: 【字符串】回文串(判断回文串)
题目链接#include <iostream>#include <cstdio>#include <cstring>using namespace std;bool judege(char str[]){ int len = strlen(str); for (int i = 0; i < len; i++) { if (str[i] != str[len-i-1]) {原创 2020-10-24 09:00:49 · 131 阅读 · 0 评论 -
1022 D进制的A+B(十进制转其他进制)
题目链接#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){ int a, b, d; scanf("%d%d%d", &a, &b, &d); int n = a + b; int ans[40], t = 0; if (n == 0) // 特判 {原创 2020-10-24 08:44:31 · 53 阅读 · 0 评论 -
问题 A: 日期差值(求两日期间相差天数)
题目链接#include <iostream>#include <cstdio>#include <cstring>using namespace std;int mouth[13][2] ={ {0, 0}, {31, 31}, {28, 29}, {31, 31}, {30, 30}, {31, 31}, {30, 30}, {31, 31}, {31, 31}, {30, 30}, {31, 31}, {30, 30}, {3原创 2020-10-23 22:11:25 · 142 阅读 · 0 评论