- 博客(11)
- 收藏
- 关注
原创 matlab十进制整数转化为二进制原码、补码
整数转化为二进制原码function y = dec2yuanma(x,N) %1<=N<=53 y=zeros(N,length(x)); for i=1:length(x) if x(i)<0 x(i)=2.^(N-1)-x(i); end d=flip(dec2bin(x(i))); b=zeros(N,1);
2020-10-08 10:38:56 2430
原创 leetcode两数之和
给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。示例:给定 nums = [2, 7, 11, 15], target = 9因为 nums[0] + nums[1] = 2 + 7 = 9所以返回 [0, 1]#include<stdio.h>#include<malloc.h>//nums:给定数组的指针//num
2020-10-06 14:12:56 140
原创 matlab二维笛卡尔坐标系
Matlab 二维笛卡尔坐标系这是一个经常会用到的程序,希望对你有帮助。clc;clear;close all;%% 绘制坐标系% 新建图窗fig=figure(1);% 确定横轴范围x=-16:11;%确定纵轴范围y=-12:11;%保持图窗,继续绘图hold on;%画横纵轴plot([0 0],[min(y)-1 max(y)+1],'k','LineWidth',1);plot([min(x)-1 max(x)+1],[0 0],'k','LineWidth',1);%
2020-09-08 10:00:53 4563
原创 最小二乘法直线拟合的C语言及matlab实现
最小二乘法的简单C语言实现这里直接上代码,理论推导参看普通最小二乘法的推导证明#include <stdio.h>//最小二乘法求散点拟合函数y=a+bx的参数a和bvoid LFM(double x[],double y[],int n){ int i; double a=0,b=0; double sum1=0,sum2=0; double mean_x=0,me...
2019-05-21 09:39:41 2392
原创 Python在输入时设置等待时间的一种方法
Python在输入时设置等待时间的一种方法# -*- coding: utf-8 -*-"""@author: __spyder__"""import timeimport msvcrtimport osdef getInput( timeout = 5): start_time = time.time() input = '' while True...
2019-04-14 14:08:05 9340 1
原创 动态规划完全背包
动态规划多重背包#include <iostream>using namespace std;int n=3;int w[]={3,4,2};int v[]={4,5,3};int W=7;//f是指标函数//s是状态变量//k是阶段变量int f(int s,int k){ if(s<=0||k>n) return 0; else if(s&...
2019-03-23 21:20:31 327
原创 哈夫曼编码C语言
哈夫曼树#include <stdio.h>//哈夫曼树节点个数为2n-1//n为叶子节点的个数//故MAX_NODE>2n-1#define MAX_NODE 200 #define MAX_SIZE 40#define INF 32767//哈夫曼树的数据结构typedef struct{ //权重 float weight ;...
2019-03-23 15:58:35 482
原创 从n个数中选出k个数
从n个数中选出k个数#include <iostream>#include <vector>#include <algorithm>using namespace std;vector<int> a;vector<int> b;void fun(int a){ cout << a << " ";...
2019-03-23 10:07:46 2567
原创 求N个数的最大公约数和最小公倍数
求N个数的最大公约数和最小公倍数#include <iostream>#include <cmath>using namespace std;//[15,40] [40,15] [15 10] [10 5] [5 0]//求两个数的最大公约数int gcd(int a,int b){ if(b==0) { return a; } else { ...
2019-03-23 01:02:51 435
原创 C/C++产生区间随机整数或小数的方法
C/C++产生区间随机整数或小数的方法#include <iostream>#include <queue>#include <cstdlib>#include <ctime>const int MIN = 0;const int MAX = 99;using namespace std;int main(){ //prior...
2019-03-19 21:01:57 1791
原创 C/C++二维数组各种传参方法
C++二维数组各种传参各种浪#include <stdio.h> #include <iostream> const int M=5; const int N=5; using namespace std; void array_init_v1(int A[][N]) { int i,j,count=0; for(i=0;...
2019-03-18 22:48:44 333
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人