![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
xiaohanstu
屌丝码农一枚!
展开
-
常用代码模板(Java)
常用代码模板(JAVA)基础算法一 快速排序void quick_sort(int q[], int l, int r){ if (l >= r) return; int i = l - 1, j = r + 1, x = q[l + r >> 1]; while (i < j) { do i ++ ; while (q[i] < x); do j -- ; while (q[j] > x);原创 2022-05-03 07:08:34 · 2820 阅读 · 0 评论 -
LeetCode 264. 丑数 II
给你一个整数 n ,请你找出并返回第 n 个 丑数 。丑数 就是只包含质因数2、3 和/或5的正整数。示例 1:输入:n = 10输出:12解释:[1, 2, 3, 4, 5, 6, 8, 9, 10, 12] 是由前 10 个丑数组成的序列。示例 2:输入:n = 1输出:1解释:1 通常被视为丑数。class Solution { public int nthUglyNumber(int n) { int [] dp = new ...原创 2022-03-26 22:32:34 · 201 阅读 · 0 评论 -
判断任意两台计算机的IP地址是否属于同一子网络
#include "OJ.h"#include#includeusing namespace std;/*功能: 判断两台计算机IP地址是同一子网络。原型: int IsSameSubNetwork(char * pcIp1, char * pcIp2, char * pcSubNetworkMask);输入参数: char * pcIP1: 计算机1的IP地址,格原创 2014-12-13 10:27:13 · 1607 阅读 · 0 评论 -
奖金提成
#include #include#include "oj.h"using namespace std;/*功能: 企业发放的奖金根据利润提成。 利润低于或等于100000元的,奖金可提10%; 利润高于100000元,低于200000元(100000<I≤200000)时; 低于100000元的部分按10%提成; 高于100000元的部分,可提成 7.5%; 200000原创 2014-12-13 09:45:01 · 1096 阅读 · 0 评论 -
求某二进制数中1的个数
#include "OJ.h"#include using namespace std;/*Description 给定一个unsigned int型的正整数,求其二进制表示中“1”的个数,要求算法的执行效率尽可能地高。Prototype int GetCount(unsigned int num)Input Param nu原创 2014-12-13 11:14:34 · 554 阅读 · 0 评论 -
求车速
#include "OJ.h"#include#includeusing namespace std;/*功能: 根据里程计算车速原型: int CalcSpeedOfCar(int iCurrentMileage, int * piCarSpeed);输入参数: int pcCurrentMileage:当前里程数(为对称数)(pcCurrentMileage原创 2014-12-13 14:22:03 · 1442 阅读 · 0 评论 -
查找同构数的数量
#include "OJ.h"#include using namespace std;bool isSameConstructNum(int m)//判断m是否是同构数{ int squareM = m*m; int initialM = m*m; int temp = 0; int partialNum =0; int interNum = 1;//存储对应位数需要成的倍原创 2014-12-11 16:09:15 · 1603 阅读 · 0 评论 -
阿姆斯特朗数
#include "OJ.h"#includeusing namespace std;/*功能: 求n(n ≤ 65536)以内的所有阿姆斯特朗数原型: int CalcArmstrongNumber(int n);输入参数: int n: n ≤ 65536返回值: n以内的阿姆斯特朗数的数量。*/bool isArmstrongNumber(in原创 2014-12-11 15:01:08 · 837 阅读 · 0 评论 -
N皇后问题
#includeusing namespace std;int vis[3][30];//分别表示列,主对角线和副对角线是否被占用,若用(row,col)表示第row行第col列位置(row,col)均从0开始//则列所在位置为col,主对角线所在位置为n-row+col,副对角线所对应的位置为row+colint ans ,MAXN;void dfs(int row){ if (r原创 2014-12-11 10:33:37 · 705 阅读 · 0 评论 -
周期串问题
#include "OJ.h"#include using namespace std;/*功能:计算字符串的最小周期。原型: int GetMinPeriod(char *string);输入参数: char * string:字符串。返回值: int 字符串最小周期。思路:使用i表示字符串可能的周期,从周期为1开始逐渐增大1,当i满足是字符串的原创 2014-12-10 18:18:47 · 767 阅读 · 0 评论 -
最长公共字串 最长公共子序列问题
http://www.cnblogs.com/dartagnan/archive/2011/10/06/2199764.html转载 2014-09-18 23:27:56 · 776 阅读 · 0 评论 -
字符串转换为整型
#includeint Myatoi(char* str){if (str == NULL){printf("invalid input");return -1;}while (*str == ' '|| *str ==''){str++;}int nSign =(*str == '-')?-1:1;if (*str == '+' || *s原创 2014-10-30 11:20:27 · 417 阅读 · 0 评论 -
树的遍历
1、树的前 中 后 续遍历:2、树的深度遍历与广度遍历:原创 2014-08-29 15:41:10 · 583 阅读 · 0 评论