- 博客(7)
- 收藏
- 关注
原创 PAT甲级 1029 Median(25 分)AC 解决内存超限
1029 Median(25 分)Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 12, and the median of S2 = { 9, ...
2018-07-05 12:31:54 4650 7
原创 1052 Linked List Sorting (25)(25 分)
1052 Linked List Sorting (25)(25 分)A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next po...
2018-07-03 15:32:27 724
原创 排列组合
排列组合从n种情况选m个选择,有多少中可能:C n m边乘边除法int C(int n, int m) { int ans = 1; for(int i = 1; i <= m; i++) ans = ans * (n - m + i) / i; return ans;}...
2018-07-03 08:31:54 203
原创 计算质因子个数
计算质因子个数计算数字 n 中有因子 a 的个数普通计算int f(int n, int a) { int ans = 0; while(n % a == 0) { ans++; n /= a; } return ans;}进阶:计算数字 !n 中有因子 a 的个数普通计算有一个公式:利用这个公式可以把时间复杂度降...
2018-07-02 15:56:56 2484 1
原创 素数筛子
素数筛子打印出1-100000内所有的素数假定所有数都是素数,然后从头遍历把素数的所有倍数(2,3,4…n倍)筛掉,则剩下的为真素数。维护一个bool类型数组,false表示没被筛掉,true表示被筛掉了。#include<stdio.h>int main() { bool num[100001] = {false}; for(int i = 2; i &...
2018-07-02 11:21:09 981
原创 快速幂
快速幂基于二分思想,时间复杂度为O(logb);当b奇数,ans = ans * (a ^ (b - 1) % m);当b偶数,ans = (a ^ (b / 2) % m) * (a ^ (b / 2) % m);当b为零,退出。#include &lt;iostream&gt;#include &lt;bitset&gt;using namespace std;lon...
2018-07-02 08:38:31 127
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人