- 博客(11)
- 收藏
- 关注
原创 使数组和能被 P 整除
原题链接 class Solution { public: int minSubarray(vector<int>& a, int p) { int n = a.size(); vector<int> s(n + 1); for(int i = 1; i <= n; i++) { s[i] = (s[i - 1] + a[i - 1]) % p; } // mod p
2020-09-20 20:20:00
337
原创 PTA-1009-说反话
title: PTA 1009 说反话 本题比较容易,这里主要是复习一下 istringstream 的用法 1. 问题描述 给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。 输入格式: 测试输入包含一个测试用例,在一行内给出总长度不超过 80 的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用 1 个空格分开,输入保证句子末...
2020-03-09 12:43:15
243
原创 c++ string
1. string初始化 string类是模板类:typedef basic_string<char> string 使用string类要包含头文件 <string> string对象初始化的方法 1. string s1("Hello"); 2. string month = "March"; 3. string s2(8, 'x'); note:可以将字符...
2020-02-22 18:41:51
280
原创 new与delete
c++ new 与 delete 1. 动态内存分配 分配一个变量 p = new T; T 是任意类型名 p 是类型为`T*`的指针 原理: 动态分配出一片大小为sizeof(T)字节的内存空间,并且将该内存空间的起始地址赋值给p。 eg: int* pn; pn = new int; pn = 5; 分配一个数组 p = new T[N]; T: 任意类型名 p: ...
2020-02-22 15:31:11
198
原创 c++关键字-const
c++关键字 const 1. 定义常量 const int MAX_VAL = 23; const double Pi = 3.14; const char* NAME = "qzylalala"[添加链接描述](https://editor.youkuaiyun.com/md/?articleId=104444353) 2. 定义常量指针 不可通过常量指针修改其指向的内容 int n, m; co...
2020-02-22 15:27:14
184
原创 c++ 引用
c++ 引用 1. 基础知识 定义引用时一定要将其初始化成引用某个变量 初始化后,他就一直引用该变量,不会再引用别的变量了 引用只能引用变量,不能引用常量和表达式 double a = 4, b = 5; // double &r1 = a * 5 编译错误 // double &r1 = 5 编译错误 double &r1 = a; double &...
2020-02-22 15:19:47
237
原创 Leetcode-42.-Trapping-Rain-Water
title:Leetcode 42. Trapping Rain Water 1. 问题描述 Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. ...
2020-02-16 20:01:43
184
原创 Leetcode-32.-Longest-Valid-Parentheses
title: Leetcode 32. Longest Valid Parentheses 1. 问题描述 Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. Example 1...
2020-02-15 20:58:50
219
原创 KNN的实现(超级具体)
期末考试考完了,重新机器学习实战,决定重新找找写代码的感觉,又手撸了一遍KNN,直接上代码,数据是在书的官网下载的 import numpy as np import matplotlib import matplotlib.pyplot as plt import operator '''从filename中加载出数据''' def getData(filename): f = op...
2019-01-13 19:08:57
617
原创 吃糖果的问题hdu problem1205
不贴具体算法,只是从数学角度分析一下(hdu Pro1205) 在网上看了不少人贴了题解,但是都是说举例发现,个人认为不是特别友善。因此写一篇小文章,分析一下这道题的数学背景。 设糖果有T种, 每一种有X1,X2,X3,…XT 个。 步骤一: 取X1,X2,X3…XT 中最小值Xmin。即标准地每种吃一个,直到把最少的那一组吃完) 那么接下来剩余的糖果种类为T - 1,每一种有X1-Xmin1,X...
2018-11-22 11:43:40
325
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅
1