PAT题解
文章平均质量分 88
浙江大学PAT题解C++版
L_Aster
..
展开
-
PAT甲级解题报告索引
PAT甲级题目地址:https://www.patest.cn/contests/pat-a-practisePAT甲级代码Github仓库已经整理更新完毕,包含最新全部代码(C++),部分代码已经加以注解,并使用尽量简单的解题思路以及简洁的代码实现:我的 Github|甲级 欢迎star或者fork,以及讨论交流关于博客,大部分已经和github同步,但是部分未更新,可能的原因有: ...原创 2017-09-22 23:15:43 · 2562 阅读 · 0 评论 -
1153 Decode Registration Card of PAT
A registration card number of PAT consists of 4 parts:the 1st letter represents the test level, namely, T for the top level, A for advance and B for basic;the 2nd - 4th digits are the test site numb...原创 2019-01-04 11:26:18 · 439 阅读 · 0 评论 -
1154 Vertex Coloring
A proper vertex coloring is a labeling of the graph’s vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k...原创 2018-12-27 16:46:59 · 341 阅读 · 0 评论 -
1155 Heap Paths
In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (i...原创 2018-12-27 14:43:09 · 396 阅读 · 0 评论 -
1152 Google Recruitment
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the picture below) for recruitment. The content is super-simple, a URL consisting of the first 10-digit p...原创 2018-12-27 14:16:03 · 333 阅读 · 0 评论 -
1151 LCA in a Binary Tree(30 分)
1151 LCA in a Binary Tree(30 分)The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.Given any two nodes in a binary tree, you ar...原创 2018-09-08 23:19:07 · 909 阅读 · 0 评论 -
1150 Travelling Salesman Problem(25 分)
1150 Travelling Salesman Problem(25 分)The “travelling salesman problem” asks the following question: “Given a list of cities and the distances between each pair of cities, what is the shortest possi...原创 2018-09-08 23:47:45 · 848 阅读 · 0 评论 -
1148 Werewolf - Simple Version (20 分)
1148 Werewolf - Simple Version (20 分)Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game,player #1 said: “Pla...原创 2018-09-12 17:12:38 · 1278 阅读 · 0 评论 -
1149 Dangerous Goods Packaging (25 分)
1149 Dangerous Goods Packaging (25 分)When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we might get ourselves in serious trou...原创 2018-09-12 17:42:34 · 597 阅读 · 0 评论 -
1147. Heaps (30)
1147. Heaps (30)#include <bits/stdc++.h>using namespace std;vector<int> A,v;int m,n;void postra(int i){ if(i<=n){ postra(2*i); postra(2*i+1); v.push_b...原创 2018-03-21 18:39:25 · 341 阅读 · 0 评论 -
1146. Topological Order (25)
1146. Topological Order (25)#include <bits/stdc++.h>using namespace std;vector<int> v[1024];int indegree[1024];bool isTopological(vector<int> &vx){ int n=vx.size(); ...原创 2018-03-21 18:40:58 · 369 阅读 · 0 评论 -
1145. Hashing - Average Search Time (25)
1145. Hashing - Average Search Time (25)#include <bits/stdc++.h>using namespace std;vector<int> v;int tsize,n,m;bool isprime(int n){ if(n<2) return 0; for(int i=2;i*i<...原创 2018-03-21 18:42:14 · 646 阅读 · 0 评论 -
1144. The Missing Number (20)
1144. The Missing Number (20)#include <bits/stdc++.h>using namespace std;int main(){ int n,val; vector<int> A; scanf("%d",&n); while(n--){ scanf("%d",&...原创 2018-03-21 18:43:25 · 430 阅读 · 0 评论 -
1140. Look-and-say Sequence (20)
1140. Look-and-say Sequence (20)#include <bits/stdc++.h>using namespace std;string lasseq(string s){ string res; int len=s.size(),i=0; while(i<len){ res+=s[i]; ...原创 2018-03-19 08:33:55 · 245 阅读 · 0 评论 -
1141. PAT Ranking of Institutions (25)
1141. PAT Ranking of Institutions (25)#include <bits/stdc++.h>using namespace std;struct node{ int rank; string school; int tws,ns; node(int r,string s,int t,int n):rank(r),...原创 2018-03-19 08:37:46 · 414 阅读 · 0 评论 -
1142. Maximal Clique (25)
1142. Maximal Clique (25)#include <bits/stdc++.h>using namespace std;vector<int> v[256];int A[256][256];void judge(vector<int> &seq){ int n=seq.size(),visit[256]={};...原创 2018-03-19 08:54:56 · 230 阅读 · 0 评论 -
1143. Lowest Common Ancestor (30)
1143. Lowest Common Ancestor (30)#include <bits/stdc++.h>using namespace std;struct TreeNode{ int val; TreeNode *left,*right; TreeNode(int v):val(v),left(NULL),right(NULL){}};...原创 2018-03-19 09:50:57 · 462 阅读 · 0 评论 -
1015. Reversible Primes (20)
A reversible prime in any number system is a prime whose “reverse” in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a pri原创 2016-08-29 15:19:42 · 421 阅读 · 0 评论 -
1019. General Palindromic Number (20)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.原创 2016-08-29 16:01:46 · 432 阅读 · 0 评论 -
1023. Have Fun with Numbers (20)
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number con...原创 2016-08-29 16:57:03 · 514 阅读 · 0 评论 -
1027. Colors in Mars (20)
1027. Colors in Mars (20)#include<stdio.h>void display(char sign[],int n);int main(){ char sign[13]={'0','1','2','3','4','5','6','7','8','9','A','B','C'}; int a,b,c; scanf("%d %d %d",&a,原创 2016-09-06 09:39:29 · 302 阅读 · 0 评论 -
1031. Hello World for U (20)
1031. Hello World for U (20)#include<stdio.h>#include<string.h>int Getn2(int N);int main(){ char s[100]; int N,n1,n2,n3; int i; gets(s); N=strlen(s); n2=Getn2(N); n1=n3=原创 2016-09-06 10:08:25 · 319 阅读 · 0 评论 -
1035. Password (20)
1035. Password (20)#include<stdio.h>#include<string.h>#include<malloc.h>struct stu{ char name[15]; char password[15]; int note;};int replace(char c[]);int main(){ int n,count=0,原创 2016-09-06 11:48:48 · 424 阅读 · 0 评论 -
1041. Be Unique (20)
1041. Be Unique (20)#include #include #include using namespace std;int nums[10004],n,idx;vectorint> v;int main(){ cin>>n; for(int i=0;i<n;++i) { cin>>idx; nums[i原创 2016-09-09 18:05:53 · 298 阅读 · 0 评论 -
1042. Shuffling Machine (20)
1042. Shuffling Machine (20)#include<stdio.h>#define N 54void display(int a[]);int main(){ int order[N+1],times,i,k; int a[N+1],b[N+1]; for(i=1;i<=N;i++)a[i]=i; scanf("%d",×);原创 2016-09-09 18:46:36 · 253 阅读 · 0 评论 -
1046. Shortest Distance (20)
1046. Shortest Distance (20)#include <bits/stdc++.h>using namespace std;int main(){ int n,sum=0,x,k; scanf("%d",&n); vector<int> val(n+1,0); for(int i=1;i<=n;...原创 2016-09-09 19:40:19 · 313 阅读 · 0 评论 -
1011. World Cup Betting (20)
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Sim原创 2016-08-29 10:59:25 · 500 阅读 · 0 评论 -
1050. String Subtraction (20)
题目:1050. String Subtraction (20)#include<stdio.h>#include<string.h>#define N 10005int main(){ char s[N],ch; int a[300]={0},i=0,n; gets(s); n=strlen(s); while((ch=getchar())!='\n原创 2016-09-10 11:50:17 · 331 阅读 · 0 评论 -
1058. A+B in Hogwarts (20)
题目:1058. A+B in Hogwarts (20)#include<stdio.h>int main(){ int G,S,K; int aG,aS,aK,bG,bS,bK; int addS=0,addG=0; scanf("%d.%d.%d %d.%d.%d",&aG,&aS,&aK,&bG,&bS,&bK); K=aK+bK; add原创 2016-09-10 12:01:16 · 430 阅读 · 0 评论 -
1061. Dating (20)
题目:1061. Dating (20) 乙级:1014. 福尔摩斯的约会 (20)原创 2016-09-10 12:07:16 · 348 阅读 · 0 评论 -
1065. A+B and C (64bit) (20)
题目:1065. A+B and C (64bit) (20)#include<stdio.h>int main(){ long long a,b,c; int n,i,tag=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%lld %lld %lld",&a,&b,&c); lo原创 2016-09-10 16:28:50 · 375 阅读 · 0 评论 -
1002. A+B for Polynomials (25)
题目:1002. A+B for Polynomials (25)#include <iostream>#include <cstdio>#include <set>using namespace std;double poly[1000];set<int,greater<int>> mst;int main(){...原创 2016-09-21 01:41:12 · 447 阅读 · 0 评论 -
1069. The Black Hole of Numbers (20)
问题:1069. The Black Hole of Numbers (20)#include<stdio.h>#define Up 1#define Down -1int Trans(int n,int state);int main(){ int n; scanf("%d",&n); while(1) { printf("%04d - %原创 2016-09-10 18:20:32 · 364 阅读 · 0 评论 -
1073. Scientific Notation (20)
题目:1073. Scientific Notation (20)#include<stdio.h>#include<string.h>int GetExp(char s[],int n);int main(){ char isign,esign; int integer,e; char decpart[10000],expart[40]; scanf("%c%原创 2016-09-10 18:25:30 · 330 阅读 · 0 评论 -
1003. Emergency (25)
题目:1003. Emergency (25)#include<stdio.h>#define MAX 500#define Inf 99999999int main(){ int vernum,arcnum,v1,v2; int a[MAX][MAX],rescue[MAX],key[MAX],dist[MAX]; int selectnum[MAX],maxres原创 2016-09-24 13:34:26 · 507 阅读 · 0 评论 -
1006. Sign In and Sign Out (25)
题目:1006. Sign In and Sign Out (25)#include using namespace std;int main(){ int m; string fname,lname,fst("24:00:00"),lst("00:00:00"); cin>>m; while(m--) { string name,原创 2016-09-24 14:42:12 · 458 阅读 · 0 评论 -
1054. The Dominant Color (20)
题目:1054. The Dominant Color (20)#include<stdio.h>#define d 4096struct store{ int a[d];}s[d];int main(){ int i,j,m,n; scanf("%d %d",&m,&n); for(i=0;i<n;i++) { for(j=0;j原创 2016-09-10 11:47:32 · 297 阅读 · 0 评论 -
1009. Product of Polynomials (25)
题目:1009. Product of Polynomials (25) 思路:哈希表#include<stdio.h>#define N 1001int main(){ int i,j,na,nb,nc=0,exp; double a[N]={0},c[N+N]={0},coe; scanf("%d",&na); for(i=0;i<na;i++)原创 2016-09-25 14:53:24 · 381 阅读 · 0 评论 -
1010. Radix (25)
题目:1010. Radix (25)#include <stdio.h>#include <string.h>long long TransDecimal(char s[],long long radix);long long BinSearch(long long n,char s[]);long long findMinRadix(char s[]);int compare(long原创 2016-10-13 19:31:11 · 378 阅读 · 0 评论 -
1012. The Best Rank (25)
题目:1012. The Best Rank (25) 思路:开了两个数组,暴力解决的;暂时没想到其它好方法;#include<stdio.h>#include<stdlib.h>#define N 1000struct stuinfo{ int id; int score[4]; int rank[4]; int bestrank; char si原创 2016-10-13 19:59:59 · 365 阅读 · 0 评论