自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 PAT 2019春 第四题

7-4 Structure of a Binary Tree (30 分)Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, a binary tree can be uniquely dete...

2019-11-18 23:47:22 135

原创 PAT19年春第三题Telefraud Detection (25 分)

Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop this crime, you are supposed to write a program to d...

2019-11-13 00:18:07 219

原创 PAT 1119 Pre- and Post-order Traversals (30 分)

#include <cstdio>#include <vector>using namespace std;vector<int> pre,in,post;bool uni=true;//中序序列是否唯一void getin(int prel,int prer,int postl,int postr){ if(prel==prer)//前序序...

2019-11-09 22:19:59 118

原创 PAT 1131 Subway Map (30 分)

#include <iostream>#include <vector>#include <cstring>using namespace std;#define MAX 10010struct Station//车站节点{ int No;//几号站 int LineNo;//几号线 Station(int no, int lineno) ...

2019-11-09 21:46:05 212

原创 PAT 1107 Social Clusters (30 分)

#include <cstdio>#include <algorithm>#include <vector>using namespace std;vector<int> father,isroot;int findfather(int x){ int a=x; while(x!=father[x]) x=...

2019-11-08 00:05:02 106

原创 PAT 1103 Integer Factorization (30 分)

#include <cstdio>#include <cmath>#include <vector>using namespace std;int n,k,p,maxfacsum=-1;//fac[i]表示i的p次方vector<int> fac,ans,temp;//初始化facvoid init(){ int i=1,t...

2019-11-07 00:13:44 157

原创 PAT 1145 Hashing - Average Search Time (25 分)

#include<iostream>#include<vector>using namespace std;bool isprime(int n){ for(int i=2;i*i<=n;i++) { if(n%i==0) return false; } return true;}in...

2019-11-06 00:09:54 67

原创 PAT 1095 Cars on Campus (30 分)

#include<iostream>#include<cstring>#include<algorithm>#include<map>using namespace std;map<string,int> maxtime;struct Car{ int time; char id[10]; bool ...

2019-11-05 23:52:24 74

原创 PAT 1096 Consecutive Factors (20 分)

#include <cstdio>int main(){ long long n,ansi=0,anslen=0; scanf("%lld",&n); for(long long i=2;i*i<=n;i++) { long long j=i,temp=1; while(1) { ...

2019-11-05 00:07:57 118

原创 PAT 1091 Acute Stroke (30 分)

#include <cstdio>#include <queue>using namespace std;struct Node{ int x,y,z;}node;int n,m,t,slice;int pixel[1290][130][61];bool inq[1290][130][61]={0};int X[6]={0,0,0,0,1,-1};...

2019-11-04 23:50:46 98

原创 PAT 1098 Insertion or Heap Sort (25 分)

#include <iostream>#include <algorithm>#include <vector>using namespace std;void downadjust(vector<int> &b,int low,int high){ int i=low,j=2*low; while(j<=hi...

2019-11-03 23:54:57 108 1

原创 PAT 1089 Insert or Merge (25 分)

#include<iostream>#include<algorithm>#include<vector>using namespace std;int main(){ int n; scanf("%d",&n); vector<int> a(n),b(n); for(int i=0;i<n;i...

2019-11-03 23:52:14 68

原创 PAT 1082 Read Number in Chinese (25 分)

#include<cstdio>#include<cstring>char num[10][10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};char wei[5][5]={"Shi","Bai","Qian","Wan","Yi"};int main(){ char s[15]; ...

2019-11-03 23:35:50 108

原创 PAT 1080 Graduate Admission (30 分)

#include<iostream>#include<vector>#include<algorithm>using namespace std;struct Stu{ int id,ge,gi,fin; vector<int> choice;};bool cmp1(Stu& a,Stu& b){ ...

2019-11-02 23:48:03 72

原创 PAT 1071 Speech Patterns (25 分)

#include <map>#include <iostream>using namespace std;map<string,int>mp;//字符合法才能算单词bool check(char c){ if(c>='0'&&c<='9') return true; else if(c&gt...

2019-11-01 23:51:35 75

原创 PAT 1067 Sort with Swap(0, i) (25 分)

#include <iostream>using namespace std;int main(){ int n,cnt=0,a[100010]; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); //从下标1开始 for(int i=1;i...

2019-11-01 23:48:38 60

原创 PAT 1060 Are They Equal (25 分)

#include <iostream>#include <string>using namespace std;int n;string deal(string str,int& e){ int k=0; //去掉前缀0 while(str.length()>0&&str[0]=='0') st...

2019-11-01 23:46:49 66

原创 PAT 1057 Stack (30 分)

#include <iostream>#include <stack>using namespace std;#define lowbit(i) ((i)&-(i))const int maxn=100010;stack<int> st;int c[maxn];void update(int x,int v){ for(int i...

2019-11-01 00:02:54 99

原创 PAT 1056 Mice and Rice (25 分)

#include <cstdio>#include <queue>using namespace std;struct mouse{ int wei; int r;}mo[1010];queue<int> qu;int main(){ int np,ng,order; scanf("%d%d",&np,&a...

2019-10-31 23:51:52 68

原创 PAT 1051 Pop Sequence (25 分)

#include <cstdio>#include <stack>using namespace std;int ans[1001];stack<int> st;int main(){ int n,m,k; scanf("%d%d%d",&n,&m,&k); for(int i=0;i<k;i++...

2019-10-30 23:55:50 129

原创 PAT 1049 Counting Ones (30 分)

#include <cstdio>int main(){ //从低位到高位,now为当前数字,left为now左边组成的数字,right为now右边组成的数字 //累计当前为now可能出现的1的个数即为答案 int n,left=0,right=0,a=1,now=1,ans=0; scanf("%d",&n); while(n/a)...

2019-10-30 23:35:29 58

原创 PAT 1044 Shopping in Mars (25 分)

#include<cstdio>int n,m;//sum[i]表示前i个元素之和int sum[100010]={0};//maxnum表示最小支付金额(有可能大于m)int maxnum=100000010;//折半查找int binary(int l,int r,int x){ int low=l,high=r,mid; while(low<...

2019-10-29 23:56:52 53

原创 PAT 1042 Shuffling Machine (20 分)

#include <cstdio>const int N=54;char mp[5]={'S','H','C','D','J'};int start[N+1],end[N+1],next[N+1];int main(){ int k; scanf("%d",&k); for(int i=1;i<N+1;++i) start...

2019-10-29 23:41:06 56

原创 PAT 1038 Recover the Smallest Number (30 分)

#include <iostream>#include <algorithm>#include <vector>using namespace std;//判断条件bool cmp(string a,string b){ return a+b<b+a;}int main(){ int n; string ans;...

2019-10-29 23:28:13 56

原创 PAT 1034 Head of a Gang (30 分)

//DFS统计连通分量个数,map自动排序(gang的head字母序)#include <map>#include <iostream>using namespace std;map<string,int> gang;map<string,int> stringtoint;map<int,string> inttostring...

2019-10-29 23:17:22 67

原创 PAT1033 To Fill or Not to Fill (25 分)

#include <cstdio>#include <algorithm>using namespace std;struct Node{ double price,dis;}node[510];//将加油站按离起点的距离排序bool cmp(const Node &a,const Node &b){ return a.dis...

2019-10-29 00:20:51 49

原创 PAT 1029 Median (25 分)

#include <cstdio>int a[200000000];const int INF = 0x7fffffff;int main(){ int n1,n2,cnt=0,temp; scanf("%d",&n1); for(int i=0;i<n1;i++) scanf("%d",&a[i]); a[...

2019-10-28 23:48:19 68

原创 PAT 1021 Deepest Root (25 分)

#include <cstdio>#include <set>using namespace std;set<int> g[100010],temp,ans;int father[100010];//isroot[i]为true表示i为根节点bool isroot[100010];int findfather(int x){ int a=...

2019-10-28 00:10:30 63

原创 PAT 1007 Maximum Subsequence Sum (25 分)

#include <cstdio>#include <vector>using namespace std;int main(){ int n; scanf("%d",&n); vector<int> v(n); //left为左边下标,right为右边下标,sum表示最大和,temp表示临时最大和,tempind...

2019-10-27 23:41:37 171

原创 PAT1151 LCA in a Binary Tree (30 分)

//已知某树根节点,若a,b分别在根节点两边,则根节点为a,b的LCA//若a,b均在根节点左边,递归查询根节点左孩子,a,b均在右边同理#include#include#includeusing namespace std;//pos存储每个数据在中序遍历序列中的下标map<int,int> pos;vector pre,in;void LCA(int inl,in...

2019-10-25 23:56:27 80

原创 PAT 1018 Public Bike Management (30 分)

```#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int inf=99999999;//g为邻接表,weight存储每个节点的单车数量,d表示从出发点到各点的最短距离int g[501...

2019-10-19 23:16:28 89

空空如也

空空如也

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

TA关注的人

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