自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(45)
  • 收藏
  • 关注

原创 hdu 1575 Tr A(矩阵快速幂)

http://acm.hdu.edu.cn/showproblem.php?pid=1575思路:直接用矩阵快速幂即可,(记得初始化数组,不然会wa)#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MOD 9973using namespac

2017-08-31 21:34:44 201

原创 hdu 1757 A Simple Math Problem(矩阵快速幂)

http://acm.hdu.edu.cn/showproblem.php?pid=1757思路:矩阵快速幂 ,通过化简,得出下面公式:所以主要的问题就是求出中间矩阵的n-9次方,设中间矩阵为A 那么A^n-9可以通过快速幂求出来,比如 A^10=A^(1010)=A^8*A^2(只需要计算5次)。核心代码:matrix matrix_quick_power(matrix a,int k)//矩阵快

2017-08-31 20:32:40 165

原创 148. Sort List (链表)

https://leetcode.com/problems/sort-list/description/题目: 链表排序思路: 我直接对值进行排序。。。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x)

2017-08-31 08:16:51 178

原创 547. Friend Circles(并查集)

https://leetcode.com/problems/friend-circles/description/题目:求朋友圈的个数。思路: 非常简单的并查集。。。class Solution {public: int fat[205]; void init() { for(int x=0;x<205;x++) fat[x]=x; } i

2017-08-29 18:47:23 449

原创 206. Reverse Linked List (链表)

https://leetcode.com/problems/reverse-linked-list/description/题目: 反转链表思路: 用一个栈,实现反转。(栈保存val就行,不能保存为链表节点)。。。。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNod

2017-08-29 18:00:10 182

原创 第14 章 预处理器之 #define

# define当我们定义#define之后,程序在预处理阶段,会将该定义进行替换。 我们已经见过define的一般用法,比如:#define max 100000。接下来讨论更多有关#define指令的用法:1 替换文本:#define reg register#define CASE break;case如果文本过长,可以定义为多行:#define DEBUG_PRINT

2017-08-28 15:44:53 363

原创 70. Climbing Stairs (dp)

https://leetcode.com/problems/climbing-stairs/description/题目: 略思路:简单dpclass Solution {public: int climbStairs(int n) { int dp[1000005]; dp[0]=dp[1]=1; for(int x=2;x<=n;x++)

2017-08-28 11:45:13 179

原创 392. Is Subsequence (模拟)

https://leetcode.com/problems/is-subsequence/description/题目: 判断一个字符串是否是另一个字符串的前缀。思路: l 表示s的下标,r表示t的下标,s[l]==t[r],l++,r++;否则r++。刚开始加了特判,错了,后面发现有一个特殊输入 “ ”, “ ”。此时长度都为0.。。。。class Solution {public: b

2017-08-27 20:33:39 189

原创 455. Assign Cookies (贪心)

https://leetcode.com/problems/assign-cookies/description/题目:将若干块蛋糕分配给若干个孩子。使得分配到蛋糕的孩子数量最大思路:贪心。将最小块蛋糕分配给需求最小的孩子,然后依次类推。class Solution {public: int findContentChildren(vector<int>& g, vector<int>&

2017-08-25 11:55:42 277

原创 343. Integer Break

https://leetcode.com/problems/integer-break/description/题目:整数拆分。解法一 思路:拆成尽量多的3。 证明: >= 得:当把输入的n拆分成几个相等的数时它们的积最大。那么问题来了,拆分成几个呢?为了方便使用导数,我们先假设我们可以把n拆分成实数。那么设每一个数为x,则一共有n/x个数。设它们的积为f(x),则f(x)=x

2017-08-24 20:13:42 153

原创 121. Best Time to Buy and Sell Stock (dp)

https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/题目:求数组中两个数差值的最大值 思路:简单dp。class Solution {public: int maxProfit(vector<int>& prices) { if(prices.empty()) return 0

2017-08-23 12:32:44 150

原创 53. Maximum Subarray (dp)

https://leetcode.com/problems/maximum-subarray/description/题目:求最大字段和思路: 直接用动态规划即可。class Solution {public: int maxSubArray(vector<int>& nums) { int max,b=0,len=nums.size(); for(int

2017-08-23 11:59:05 256

原创 303. Range Sum Query - Immutable (前缀数组)

https://leetcode.com/problems/range-sum-query-immutable/description/题目: 求数组某段区间的值。 思路:直接用前缀和就行了,注意特殊情况的考虑。class NumArray {public: NumArray(vector<int> nums) { if(nums.empty()) return ;

2017-08-23 11:51:42 169

原创 Stack Overflow

在Stack Overflow上看到这样一段代码int * foo(){ int a = 5; return &a;}int main(){ int* p = foo(); cout << *p; *p = 8; cout << *p;}运行结果:我的想法是:虽然函数调用结束,但是该内存并没有被销毁,由于p指针指向该内存并且后面并没有其它的函数

2017-08-22 13:00:51 459

原创 203. Remove Linked List Elements(链表)

https://leetcode.com/problems/remove-linked-list-elements/description/题目:删除链表中的元素思路:直接用2个指针即可。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; *

2017-08-22 10:27:56 194

原创 计算机经典书籍

1.计算机科学概论 计算机科学概论2.计算机数学基础 高等数学 线性代数 概率论与数理统计 离散数学及其应用 离散数学教程(北大版) 什么是数学3.C语言 谭浩强C程序设计 C primer plus The C programming language C和指针 C专家教程 C陷阱与缺陷 c语言解惑 C标准库 你必须知道的495个C语言问题4.算法与数据结构

2017-08-21 19:29:47 393

原创 160. Intersection of Two Linked Lists(链表)

https://leetcode.com/problems/intersection-of-two-linked-lists/description/题目:找2个链表的公共节点。思路:遍历2遍,然后判断。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *nex

2017-08-21 18:25:04 137

原创 83. Remove Duplicates from Sorted List (链表)

https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/题目: 去除链表中的重复元素。思路: 用2个指针遍历即可。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode

2017-08-21 17:57:03 150

原创 237. Delete Node in a Linked List(链表)

https://leetcode.com/problems/delete-node-in-a-linked-list/description/题目:将链表中的某个节点删除,但是给定的节点就是需要删除的节点 思路:采用替换原则。例如 1->2->3->4 需要删除2,先进行值替换得到: 1->3->3->4 , 然后删除 “需要删除的节点”的下一节点得到 1->3->4。/** * Definit

2017-08-21 17:41:15 193

原创 141. Linked List Cycle (链表)

https://leetcode.com/problems/linked-list-cycle/description/题目:判断链表是否存在环。用2个指针,慢指针每次加一,快指针每次加二,如果有一个指针为NULL ,则没有环,如果两个指针相等,则存在环。/** * Definition for singly-linked list. * struct ListNode { * int

2017-08-21 17:10:41 166

原创 112. Path Sum (二叉树)

https://leetcode.com/problems/path-sum/description/题目大意:给定一个二叉树和一个值sum,判断是否存在一个从根节点到叶子节点的路径,使得路径上每个节点值之和等于sum?第一种解法:递归/** * Definition for a binary tree node. * struct TreeNode { * int val; *

2017-08-20 20:31:02 201

原创 561. Array Partition I (数组)

https://leetcode.com/problems/array-partition-i/description/题意:给定一个长度为2n(偶数)的数组,分成n个小组,返回每组中较小值的和sum,使sum尽量大 思路:直接排序,然后将下标为偶数的元素累加即可(下标从0开始)。class Solution {public: int arrayPairSum(vector<int>& n

2017-08-20 19:33:34 214

原创 文章标题

推荐一个 技术博客 http://112.126.74.142/note

2017-08-18 12:06:51 228

转载 值得推荐的C/C++框架和库

值得推荐的C/C++框架和库 Webbench是一个在linux下使用的非常简单的网站压测工具。它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接去测试网站的负载能力。Webbench使用C语言编写, 代码实在太简洁,源码加起来不到600行。* 文章网址 https://www.ezlippi.com/blog/201

2017-08-18 12:01:09 191

转载 文章标题

[置顶] 写给准备参加秋招的学弟学妹们~一定要来看哦~http://blog.csdn.net/liuqiyao_01/article/details/26567237

2017-08-18 11:32:11 234

原创 文章标题

《编程之法:面试和算法心得》 https://github.com/julycoding/The-Art-Of-Programming-By-July/blob/master/ebook/zh/Readme.md

2017-08-18 11:25:51 175

原创 51nod 1007 正整数分组

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1007就是一个简单的01背包问题。#include<iostream>#include<algorithm>#include<stdio.h>#define maxn 105#define max1 10005using namespace std;int bei

2017-08-16 23:03:23 155

原创 51nod 1640 天气晴朗的魔法

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1640思路:先求最小生成树,最小生成树的最大值肯定是最小的,然后再求一次最大生成树(所有大于最小生成树的最大值的边抛弃)#include<iostream>#include<algorithm>#include<stdio.h>#define maxn 100005u

2017-08-14 16:31:43 212

原创 51nod 1240 莫比乌斯函数

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1240#include <bits/stdc++.h>using namespace std;typedef long long LL;LL Miu( LL n ) { /// 莫比乌斯函数板子。 LL m = 1; for(LL i = 2; i *

2017-08-14 16:02:08 175

原创 51nod 1307 绳子与重物

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1307直接用并查集就可以了。#include<iostream>#include<cstdio>#include<cstring>#include<stack>#define maxn 50005using namespace std;int s[maxn];i

2017-08-14 11:20:05 201

原创 51nod 1068 Bash游戏 V3

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1068Bash游戏的变形,通过SG函数找出规律: 0 1 2 3 4 5 6 7 8 9 0 1 2 0 1 2 0 1 2 0发现n%3==0的话,就是奇异局势,则B胜,否则A胜。#include<iostream>#include<cstring>#include

2017-08-13 21:05:14 108

原创 51nod 1067 Bash游戏 V2

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1067Bash游戏的变形,我是通过SG函数找出规律的:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 0 1 0 1 2 3 2 0 1 0 1 0 1 2 3 2 0 1 0 1 2 3

2017-08-13 20:54:15 236 1

原创 51 nod 1072 威佐夫博弈

http://www.51nod.com/onlineJudge/submitDetail.html#!judgeId=315179最简单的威佐夫博弈,直接上代码:#include<iostream>#include<cmath>#include<stdio.h>#include<algorithm>#include<stack>#include<map>#include<string>

2017-08-13 20:19:18 189

原创 1 Two Sum (数组)

https://leetcode.com/problems/two-sum/description/在一个数组中,找出2个数的和等于给定的数。直接用map映射即可。class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { map<int, int> m; vect

2017-08-13 19:48:02 183

原创 c++对象的成员变量

c++对象的成员变量在进程内存中的存放位置一个典型的进程地址空间:对于我们自定义类型对象的成员变量来说,它在进程运行时,应该储存在哪里??Data区?堆区??栈区??我们猜想它在栈区,现在来验证一下。 先写如下代码:#include&lt;iostream&gt;#include&lt;unistd.h&gt;using namespace std;int s2=0;...

2017-08-12 23:07:23 1580

原创 hdu 2602 简单的01背包

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2602最简单的01背包,用一维数组优化。。#include<stdio.h>#include<algorithm>#define maxn 1005using namespace std;int t,n,v;int wight[maxn];int value[maxn];int beibao

2017-08-11 19:11:28 229

原创 hdu 2544 基础最短路

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2544基础最短路,直接用迪杰斯特拉即可(注意会输入重边).#include<stdio.h>#define MAX 0x3fffffffint map[105][105],dis[105];bool use[105];int n,m;void dijk(int start){ int

2017-08-11 17:43:05 216

原创 hdu 1009 贪心算法

题目 链接 http://acm.hdu.edu.cn/showproblem.php?pid=1009题意:一共有n个房子,每个房子里有老鼠喜欢吃的javabeans,但是每个房间里的javabeans的价格不一样。老鼠用m元,问m元最多可以卖多少javabeans,其中每个房间里的javabeans可以被分割。思路 : 先求单价,然后排个序就行了。(用float 貌似精度不够。。。。)#incl

2017-08-11 15:21:10 326

原创 hdu 2188 简单巴什博奕

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2188仍然是简单的巴什博奕#include <iostream>#include <stdio.h>#include <string.h>#include <cmath>#include <algorithm>using namespace std;int c,n,m;int main()

2017-08-11 10:24:45 209

原创 hdu 1846 基础巴什博奕

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1846思路: 简单的巴什博奕,如果n%(m+1)==0,则为奇异局面,后手赢,否则为先手赢。 #include <iostream>#include <stdio.h>#include <string.h>#include <cmath>#include <algorithm>using na

2017-08-11 10:05:42 211

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除