自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(22)
  • 问答 (2)
  • 收藏
  • 关注

原创 1118 Birds in Forest (25 分)

1.使用并查集2.使用路径压缩,否则超时。#include <iostream>#include <cstdio>#include <algorithm>#include <vector>using namespace std;const int maxn=10005;int father[maxn];int vis[maxn]={...

2019-09-08 13:08:45 84

原创 1115 Counting Nodes in a BST

1.使用链表表示二叉树2.深度优先搜索3.构建二叉树#include <iostream>#include <cstdio>#include <algorithm>#include <vector>using namespace std;struct node{ int v; node *right,*left;};node*...

2019-09-07 19:24:16 79

原创 1114 Family Property

并查集#include <iostream>#include <cstdio>#include <algorithm>#include <vector>using namespace std;struct Node{ int id,fid,mid,k,num,area; int child[10];}node[1005];stru...

2019-09-07 18:29:46 140

原创 1110 Complete Binary Tree (25 分)

按照层序给树排下标,若最大下标值等于节点数,该树就是完全二叉树。#include <iostream>#include <cstdio>#include <vector>#include <cstring>using namespace std;struct node{ int l,r;}Node[25];int maxn,ans=...

2019-08-30 20:20:20 73

原创 1108 Finding Average (20 分)

sscanf用法sprintf用法#include <iostream>#include <cstdio>#include <string.h>using namespace std;int main() { int n, cnt = 0; char a[50], b[50]; double temp, sum = 0.0;...

2019-08-29 15:42:22 73

原创 1106 Lowest Price in Supply Chain (25 分)

深度优先搜索求最深叶子结点#include <iostream>#include <algorithm>#include <vector>using namespace std;vector<int> member[100010];int mindepth=0x7fffffff,num=1;void dfs(int index,int ...

2019-08-29 13:34:51 101

原创 1102 Invert a Binary Tree (25 分)

反转一个二叉树:在cmp函数和dfs函数中做调整#include <iostream>#include <algorithm>#include <vector>using namespace std;struct node{ int id,r,l,index,level;} a[100];vector<node> v1;void d...

2019-08-27 14:14:30 41

原创 1064 Complete Binary Search Tree (30 分)

二叉查找树的左右子节点下标分别为2x 2x+1,中序遍历是有序的。#include <iostream>#include <algorithm>#include <vector>#include <set>using namespace std;int digit[1010],tree[1010];int n,num=0;void i...

2019-08-22 15:25:12 70

原创 1094 The Largest Generation (25 分)

dfs算法#include <iostream>#include <algorithm>#include <vector>using namespace std;int book[100]={0};vector<int> v[110];void dfs(int index,int level){ book[level]++; for...

2019-08-21 17:20:28 82

转载 1098 Insertion or Heap Sort (25 分)

参考柳神做法

2019-08-20 21:43:19 79

原创 1099 Build A Binary Search Tree

二叉查找树中序遍历是有顺序的,层序遍历使用队列#include <iostream>#include <algorithm>#include <cstring>#include <queue>using namespace std;struct node{ int key,num; int left,right;}Node[100]...

2019-08-20 21:40:06 43

原创 1073 Scientific Notation (20 分)

1.stoi()函数的运用,将string转化为int2.substr()函数的运用。s.substr(在s内要截取的起始位置,长度(不填则截取到最后))。#include <iostream>#include <algorithm>#include <cmath>using namespace std;int main(){ string s;...

2019-08-18 17:38:12 57

原创 1085 Perfect Sequence (25 分)

使用two pointers#include <iostream>#include <vector> #include <algorithm>using namespace std;int main(){ int n,q; cin>> n >> q; long long seq[100010]; for(int i=0...

2019-08-16 21:41:09 47

原创 1067 Sort with Swap(0, i)

1.使用pos[]数组的下标表示输入的数,值表示存在的顺序,可以避免交换时的元素查找导致超时。2.swap(pos[0],pos[pos[0]]);表示交换0所在位置与该位置应该存在的数的位置。3.当0不是存在第0位时交换,0存在第0位时与k交换,继续循环。4.使用num表示已经放在最终位置的数的个数,且num<n-1#include <iostream>#includ...

2019-08-16 17:36:21 49

原创 1084 Broken Keyboard (20 分)

string::npos用来表示一个不存在的位置,当find()没有找到时返回#include <iostream>using namespace std;int main(){ string s1,s2,ans; cin >> s1 >> s2; for(int i=0;i<s1.length();i++){ if(s2.find(s1[...

2019-08-16 10:32:02 156

原创 1077 Kuchiguse (20 分)

getline(cin,c)前的scanf()要使用\n吸收回车,否则输入会少一行string的长度用s.length()获得,char[]的长度用strlen(c)获得string容器支持begin()和end()截取字符串操作使用方法string.substr(left,right)#include <iostream>#include <algorithm&g...

2019-08-12 22:35:38 76

原创 1065 A+B and C (64bit) (20 分)

大整数运算:当a b都大于0,a+b溢出时,a+b<0;当a b都小于0,a+b溢出时,a+b>=0;#include <iostream>#include <algorithm>#include <cmath>using namespace std;int main(){ int n; long long a,b,c,res;...

2019-08-12 17:26:38 52

原创 1096 Consecutive Factors (20 分)

质因分解#include <iostream>#include <algorithm>#include <cmath>using namespace std;int main(){ int n,ansI=-1,ansLen=0; cin >> n; int sqr=(int)sqrt(1.0*n); for(int i=2;i&l...

2019-08-12 11:02:12 44

原创 1059 Prime Factors (25 分)

质因子分解#include <iostream>#include <algorithm>#include <cmath>#include <cstring>using namespace std;const int maxn=100000;bool is_prime(int a){ if(a==1) return false; in...

2019-08-11 22:19:47 41

原创 最大公约数和最小公倍数

最大公约数辗转相除法int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); }最小公倍数求出最大公约数d;lcm(a,b)=ab/d;

2019-08-11 18:46:53 111

原创 1093 Count PAT's (25 分)

The string APPAPT contains two PAT’s as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.Now g...

2019-08-06 20:38:40 137

原创 PAT 1025 PAT Ranking (25 分)

PAT 1025 PAT Ranking (25 分)Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several...

2019-08-06 19:05:06 114

空空如也

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

TA关注的人

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