![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PAT
二狗子的天下
这个作者很懒,什么都没留下…
展开
-
1147 Heaps (30 分)
#include <cstdio>using namespace std;const int maxn=1020;int N,M;int level[maxn];bool isMax(int root){ if(root*2>N){ return true; } if(root*2+1>N) return level[root]>=level[root*2]; int t=(level[root*2]>leve原创 2021-09-10 11:44:38 · 69 阅读 · 0 评论 -
1140 Look-and-say Sequence
#include <iostream>#include <string>using namespace std;int main(void){ string str,tstr; int Time; cin>>str>>Time; if(Time==1){ cout<<str; return 0; } for(int i=2;i<=Time;i++){原创 2021-09-10 09:47:17 · 70 阅读 · 0 评论 -
1105 Spiral Matrix
简单模拟题#include <cstdio>#include <algorithm>#include <cmath>using namespace std;int N;const int maxn=10020;const int INF=10000000;int num[maxn];bool cmp(int a,int b){ return a>b;}int main(void){ scanf("%d",&N);原创 2021-08-22 12:10:30 · 50 阅读 · 0 评论 -
1017 Queueing at Bank
注意点:客户迟到和早到所带来的影响,后面三个测试点不过的原因在这。#include <cstdio>#include <algorithm>using namespace std;const int INF=1000000;const int maxn=10010;int Window[200];struct customer{ int arrive_time,process_time,wait_time;//s为单位}Cus[maxn];int cor[原创 2021-08-22 10:49:17 · 64 阅读 · 0 评论 -
1069 The Black Hole of Numbers
注意此组测试数据:#include <cstdio>#include <algorithm>using namespace std;int num[10];bool cmp(int a,int b){ return a>b;}void divide(int n){ for(int i=3;i>=0;i--){ num[i]=n%10; n/=10; }}int merge(){ i原创 2021-08-21 17:14:57 · 52 阅读 · 0 评论 -
1088 Rational Arithmetic (20 分)
#include <cstdio>#include <algorithm>using namespace std;struct Fraction{ long int up,down;};long int gcd(long int a,long int b){ if(b==0) return a; return gcd(b,a%b);}Fraction reduction(Fraction a){ if(a.down<0){原创 2021-08-21 16:32:05 · 58 阅读 · 0 评论 -
PAT(甲级)2014年冬季考试 Insert or Merge
其中step/2<N的意思是step/2=N-1的时候,此时左半边包括了整个数组,确保整个数组都整合有序#include <cstdio>#include <algorithm>using namespace std;const int maxn =110;int initiate[maxn];int tmp[maxn];int target[maxn];int pos,N;bool isInsertionSort(){ for(int i=1;i原创 2021-08-21 15:06:21 · 55 阅读 · 0 评论 -
1014 Waiting in Line 简单队列模拟题
#include <cstdio>#include <queue>#include <algorithm>using namespace std;const int maxn=1010;struct window{ int endtime; int poptime; queue<int> q;}Window[21];int ans[maxn];int needtime[maxn];int N,M,K,Q;int i原创 2021-08-19 21:04:21 · 47 阅读 · 0 评论 -
1023 Have Fun with Numbers (20 分)
建议使用结构体引用或指针作为函数传递参数。#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct bign{ int d[1000]; int len; bign(){ memset(d,0,sizeof(d)); len=0; }};void change(char str[],bi原创 2021-08-19 09:22:33 · 45 阅读 · 0 评论 -
1104 Sum of Number Segments PAT (Advanced Level) Practice
排列组合题:对给定序列中任一个数,讨论该数在给定序列对应的所有连续序列中出现的次数,将该次数乘以该数得出该数对总和的贡献。遍历给定序列中每一个数,统计贡献即得总和。对于次数求法,该数两边可能情况数相乘即可(记得统计可能为空的情况)。例如,本题中的序列{ 0.1, 0.2, 0.3, 0.4 },对0.3来讲,左边可能情况为() (0.1) (0.1, 0.2),情况数为3,右边可能情况为() (0.4),情况数为2。显然可发现,对0.3来讲,任一边情况数=0.3对应边数字的个数+1;因此,将该规律抽象出来即原创 2021-08-18 11:28:09 · 62 阅读 · 0 评论 -
1042 Shuffling Machine (20 分) PAT (Advanced Level) Practice
#include <cstdio>using namespace std;const int size=55;char mp[]={'S','H','C','D','J'};int start[size];int end[size];int order[size];int k;int main(void){ scanf("%d",&k); for(int i=1;i<=size-1;i++){ scanf("%d",&or原创 2021-08-16 21:59:36 · 50 阅读 · 0 评论 -
1046 Shortest Distance PAT (Advanced Level) Practice
#include <cstdio>#include <algorithm>using namespace std;const int maxn=100010;int d[maxn],N;int main(void){ scanf("%d",&N); for(int i=1;i<=N;i++){ int dis; scanf("%d",&dis); d[i]=d[i-1]+dis;原创 2021-08-16 21:00:52 · 56 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1070 Mooncake (25 分)
1070 Mooncake (25 分)Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the region’s culture. Now given the inventory amounts and the原创 2021-08-13 18:46:34 · 54 阅读 · 0 评论 -
PAT (Advanced Level) Practice1084 Broken Keyboard
不用哈希表,直接用string里一些性质就完#include <string>#include <iostream>using namespace std;int main(void){ string s1,s2,S; cin >> s1>>s2; for(string::iterator it=s2.begin();it!=s2.end();it++){ if(*it>='a' && *it<='z'){原创 2021-08-12 20:28:35 · 53 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1012 The Best Rank 论如何把代码写成自己逐渐看不懂得样子
1012 The Best Rank (25 分)To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we enc原创 2021-08-12 17:52:57 · 47 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1097 Deduplication on a Linked List
#include <cstdio>#include <algorithm>using namespace std;const int maxn=10010;const int Max=100010;bool vis[maxn]={false};struct node{ int address,data,next,order;}list[Max];int N,head;bool cmp(node a, node b){ return a.order<b.原创 2021-08-08 09:29:05 · 61 阅读 · 0 评论 -
PAT 1051 Pop Sequence
#include <cstdio>#include <stack>using namespace std;const int maxn=1001;stack<int> s;int index;int M,N,k;int xulie[maxn];int main(void){ scanf("%d%d%d",&M,&N,&k); for(int i=1;i<=k;i++){ for(int j=1;j<=N;j+原创 2021-08-08 08:22:18 · 49 阅读 · 0 评论 -
PAT 1074 Reversing Linked List
模板题。注意:题目给的结点不一定全能用上。第六个测试点出现错误的,建议检查一下有效结点找的是否准确(比如说个数啊之类的,我就是一开始错在个数上)。#include <cstdio>#include <algorithm>using namespace std;const int maxn=100010;struct node{ int address,data,next,order;}list[maxn];int head,N,k;bool cmp(nod原创 2021-08-07 17:52:29 · 71 阅读 · 0 评论 -
PAT A1053
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int maxn=110;int N,M,S;int w[maxn];vector<int> Adj[maxn];vector<int> path; int W;void DFS(int i){ if(Adj[i].原创 2021-08-03 09:16:06 · 37 阅读 · 0 评论 -
PAT (Advanced Level) Practice 1021 Deepest Root (25 分)
#include <cstdio>#include <cstring>#include <vector>#include <set>#include <queue>using namespace std;const int maxn=10010;vector<int> Adj[maxn];int N;set<int> droot;bool vis[maxn];bool inq[maxn];int e原创 2021-07-31 18:09:48 · 62 阅读 · 0 评论