自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

姚军

富贵非吾愿,帝乡不可期。怀良辰以孤往,或植杖而耘耔。

  • 博客(205)
  • 收藏
  • 关注

原创 不用额外变量交换两个整数的值

x^x = 00^x = x异或位运算#include <cstdio>#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;int main(){ int m, n; cin>&...

2019-09-30 15:09:14 113

原创 字符串的统计字符串

字符串+双指针#include <cstdio>#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;int main(){ string str; getline(cin, str); ...

2019-09-30 14:58:21 83

原创 判断两个字符串是否互为旋转词

#include <cstdio>#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;int main(){ int m, n; cin>>m>>n; string...

2019-09-30 14:36:23 98

原创 判断两个字符串是否为变形词

#include <cstdio>#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;int main(){ int m, n; cin>>m>>n; string...

2019-09-30 14:32:10 146

原创 在行列都排好序的矩阵中找指定的数

#include <cstdio>#include <iostream>#include <vector>#include <algorithm>using namespace std;const int N = 1003;int arr[N][N];int main(){ int m, n, x; scanf("%d%d%d",...

2019-09-30 14:20:41 140

原创 翻转字符串(1)

#include <cstdio>#include <iostream>#include <vector>#include <algorithm>using namespace std;int main(){ char c; string str; int flag = false; while(cin>>str){ ...

2019-09-30 13:47:05 132

原创 子数组的最大累加和问题

DP只要累加和大于零 前面的这部分就有利用价值 在过程中求最大值#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 1e5+5;typedef long long LL;int arr[N];int main(){ i...

2019-09-30 11:30:50 195

原创 计算数组的小和

类似于逆序对的问题使用归并算法注意整型会溢出,需要使用长整型。#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 1e5+5;typedef long long LL;int A[N];LL merge(int l, ...

2019-09-30 11:17:18 337

原创 矩阵的最小路径和

dp+滚动数组注意边界设定为无穷大,因为每次要求最小值。#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 2003;int arr[N][N];int dp[N];int main(){ int m, n; scan...

2019-09-30 09:40:29 178 1

原创 数组中未出现的最小正整数

#include <iostream>#include <cstdio>using namespace std;const int N = 1e6+3;int arr[N];int main(){ int n; scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", arr+i); i...

2019-09-30 09:26:03 169

原创 1057. 股票买卖 IV

状态机注意买卖的定义#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int N = 100010, M = 110, INF = 0x3f3f3f3f;int n, m;int w[N];int f[N][M][2];i...

2019-09-29 20:21:13 131

原创 1049. 大盗阿福

自动机0——> 00——>11——>0因为不许抢两个相邻商店 所以不允许从1到1#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int N = 100010, INF = 0x3f3f3f3f;int n...

2019-09-29 19:58:54 101

原创 898. 数字三角形

xy zx位置上的最大值取决于y和z的最大值加上x本身的值,可以用一维数组从底至顶迭代。边界条件是最底层的最值就是这一行本身。#include <iostream>#include <algorithm>using namespace std;const int N = 505;int a[N][N], g[N];int main(){ int ...

2019-09-29 18:01:45 132

原创 面试题12:矩阵中的路径

class Solution {public: bool hasPath(vector<vector<char>>& matrix, string str) { for(int i = 0; i < matrix.size(); i++){ for(int j = 0; j < matrix[i].siz...

2019-09-28 07:50:39 115

原创 面试题11:旋转数组的最小数字

class Solution {public: int findMin(vector<int>& nums) { int n = nums.size() - 1; if(n < 0) return -1; while(n > 0 && nums[n] == nums[0]) n--; ...

2019-09-28 07:48:45 69

原创 面试题10:斐波那契数列

题目链接class Solution {public: int Fibonacci(int n) { int f[40]; f[0] = 0; f[1] = 1; for(int i = 2; i <= n; i++){ f[i] = f[i-1] + f[i-2]; ...

2019-09-27 10:43:00 111

原创 面试题9:用两个栈实现队列

题目链接class MyQueue {public: /** Initialize your data structure here. */ MyQueue() { } stack<int> stk, cache; /** Push element x to the back of queue. */ void co...

2019-09-27 10:41:56 71

原创 面试题8:二叉树的下一个节点

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode *father; * TreeNode(int x) : val(x), left(NULL), righ...

2019-09-27 10:40:53 59

原创 面试题7:重建二叉树

题目链接/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */...

2019-09-27 10:40:10 126

原创 面试题6:从尾到头打印链表

题目链接/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: vector&...

2019-09-27 10:38:40 87

原创 7-4 Dijkstra Sequence (30 分)

考查知识点:Dijkstra算法手动模拟一下就能看出规律#include <iostream>#include <cstdio>#include <stack>#include <algorithm> #include <vector> using namespace std;const int N =1e3+3;co...

2019-09-27 09:25:15 461

原创 7-3 Postfix Expressio (25 分)

考查的知识点:只有右子树的时候需要特殊处理#include <iostream>#include <cmath>#include <algorithm>#include <vector>#include <string>using namespace std;const int N = 25;int Root = 1;...

2019-09-27 09:23:54 138

原创 7-2 Merging Linked Lists (25 分)

考查的知识点:链表的静态存储PAT的经典类型题#include <iostream>#include <cstdio>#include <stack>#include <unordered_map> #include <algorithm> using namespace std;const int N =1e5+3;...

2019-09-27 09:22:47 995

原创 7-1 Forever (20 分)

考查的知识点:1.暴力会超时,需要剪枝2.输出不唯一时,先按照n排序,再按照A排序3.没有的时候输出No Solution#include <iostream>#include <cstdio>#include <stack>#include <algorithm> #include <vector>#include &...

2019-09-27 09:21:50 294

原创 1130 Infix Expressio (25 分)

之前因为偷懒没有刷这道题,结果秋季的PAT考试就考到了。主要是理解括号的插入位置以及遍历的规则。首先需要找到根节点,其次是非根节点和叶子点需要加括号。#include <iostream>#include <cmath>#include <algorithm>#include <vector>#include <string&gt...

2019-09-27 08:24:38 69

原创 7-46 新浪微博热门话题 (30 分)

题解这个30分不好拿呀,可以借鉴的知识点:map根据value排序,其实是用vector中的pair进行排序。首先题目读错了,忽略了还有数字,注意到这个问题以后,第三个测试点还是过不去。后来看了别人的博客才发现,原来除了字母和数字的其他字符,要先替换成空格才行。每个话题在一行中只标记一次。别人的测试样例输入4This is a #test of 1 topic#.Another...

2019-09-26 17:57:10 659

原创 7-50 畅通工程之局部最小花费问题 (35 分)

并查集kruskal算法的应用需要先将连通的点合并起来,然后再查询。由于集合的原因,肯定不会包含重复的点。#include <iostream>#include <cstdio>#include <string>#include <unordered_map>#include <algorithm>using names...

2019-09-26 16:18:47 656

原创 7-16 一元多项式求导 (20 分)

坑点当没有合适的输出内容时, 需要输出0 0#include <iostream>#include <cstdio>#include <string>#include <unordered_map>using namespace std; const int N = 1e3+7;struct node{ int coef; int...

2019-09-26 15:55:13 157

原创 7-15 QQ帐户的申请与登陆 (25 分)

#include <iostream>#include <cstdio>#include <string>#include <unordered_map>using namespace std; int main(){ int n; cin>>n; unordered_map<string, string> m...

2019-09-26 15:11:57 294

原创 6-11 先序输出叶结点 (15 分)

void PreorderPrintLeaves( BinTree BT ){ if(!BT) return; if(!BT->Left && !BT->Right){ printf(" %c", BT->Data); return; } PreorderPrintLeaves(BT->Left...

2019-09-26 13:14:47 1092

原创 团体程序设计天梯赛题解

L1-001 Hello World (5 分)L1-002 打印沙漏 (20 分)L1-003 个位数统计 (15 分)L1-004 计算摄氏温度 (5 分)L1-005 考试座位号 (15 分)L1-006 连续因子 (20 分)L1-007 念数字 (10 分)L1-008 求整数段和 (10 分)L1-009 N个数求和 (20 分)L1-010 比较大小 (10 分)...

2019-09-26 10:31:35 3184 4

原创 7-30 字符串的冒泡排序 (20 分)

#include <iostream>#include <cstdio>#include <algorithm>#include <string>#include <vector>using namespace std;string arr[101];int main(){ int n, k; cin>>n&...

2019-09-26 10:26:28 559

原创 7-29 删除字符串中的子串 (20 分)

#include <iostream>#include <cstdio>#include <algorithm>#include <string>using namespace std;int main(){ string str, s; getline(cin, str); getline(cin, s); while(1){...

2019-09-26 10:16:46 373

原创 7-25 念数字 (15 分)

#include <iostream>#include <cstdio>#include <algorithm>#include <string>using namespace std;string mp[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; int mai...

2019-09-26 10:10:13 698

原创 7-10 计算工资 (15 分)

#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int main(){ int n, h; cin>>n>>h; if(n < 5){ //新员工 if(h <= 40) printf("%.2f", h...

2019-09-26 10:06:00 570

原创 7-9 用天平找小球 (10 分)

#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int main(){ int a, b, c; int sum = 0; cin>>a>>b>>c; sum=a^b^c; if(sum == a) cou...

2019-09-26 09:58:53 138

原创 P2 九宫格输入法 (15 分)

假设有九宫格输入法键盘布局如下: [ 1,.?! ] [ 2ABC ] [ 3DEF ] [ 4GHI ] [ 5JKL ] [ 6MNO ] [ 7PQRS ] [ 8TUV ] [ 9WXYZ ] [ 0空 ]注意: 中括号[ ]仅为了表示键盘的分隔,不是输入字符。每个中括号中,位于首位的数字字符即是键盘的按键,按一下即可输入该数字字符。多次按同一个键,...

2019-09-25 13:28:59 664

原创 P8 叶节点求和 (15 分)

对给定的有N个节点(N>=0)的二叉树,求叶节点元素之和。输入格式:第一行是一个非负整数N,表示有N个节点第二行是一个整数k,是树根的元素值接下来有N-1行,每行是一个新节点,格式为 r d e 三个整数,r表示该节点的父节点元素值(保证父节点存在);d是方向,0表示该节点为父节点的左儿子,1表示右儿子;e是该节点的元素值。输出格式:树中叶节点元素之和 (保证在整型变量范围之内...

2019-09-23 21:38:49 1222

原创 P9 中序遍历树并判断是否为二叉搜索树 (15 分)

对给定的有N个节点(N>=0)的二叉树,给出中序遍历序列,并判断是否为二叉搜索树。题目保证二叉树不超过200个节点,节点数值在整型int范围内且各不相同。输入格式:第一行是一个非负整数N,表示有N个节点第二行是一个整数k,是树根的元素值接下来有N-1行,每行是一个新节点,格式为r d e 三个整数,r表示该节点的父节点元素值(保证父节点存在);d是方向,0表示该节点为父节点的左儿...

2019-09-23 21:32:27 1712 3

原创 tkinter沿着正方形运动

画正方形from tkinter import *import numpy as npimport timetk = Tk()tk.title('shepherd')tk.wm_attributes("-topmost", 1)Width = 600Height = 600canvas = Canvas(tk, width=Width, height=Height, bg='...

2019-09-23 15:15:20 207

空空如也

空空如也

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

TA关注的人

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