
PAT甲级
Uranus_A
这个作者很懒,什么都没留下…
展开
-
1102 Invert a Binary Tree (25 分)-------如何反转二叉树+二叉树的层序和中序遍历
#include<iostream>#include<queue>using namespace std;struct Node{ int lchild; int rchild;}node[110];bool isnotroot[110]={false};int n,num=0;void print(int id){ cout<<id; num++; if(num!=n) cout<&原创 2022-02-10 14:53:24 · 407 阅读 · 0 评论 -
1086 Tree Traversals Again (25 分)
#include<iostream>#include<stack>#include<queue>using namespace std;struct node{ int data; node* lchild; node* rchild;};int pre[50],in[50];int n;node* create(int prel,int prer,int inl,int inr){ if(prel>prer原创 2022-02-09 21:37:44 · 149 阅读 · 0 评论 -
1053 Path of Equal Weight (30 分)-------带权树的DFS
#include<iostream>#include<vector>#include<algorithm>using namespace std;const int maxn=110;struct Node{ int weight; vector<int> child;}node[maxn];bool cmp(int a,int b){ return node[a].weight>node[b].weight原创 2022-02-09 16:28:54 · 345 阅读 · 0 评论 -
1020 Tree Traversals (25 分)/中序遍历+后序遍历转为层次遍历
#include<iostream>#include<queue>#include<algorithm>#include<stdio.h>using namespace std;struct node{ int data; node* lchild; node* rchild;};const int maxn=50;int n,pre[maxn],post[maxn],in[maxn];node* create(原创 2022-02-09 11:29:00 · 95 阅读 · 0 评论 -
1033 To Fill or Not to Fill (25 分) 贪心算法
首先讲一下思路。这道题是一个贪心算法的题,大体方法就是0.寻找比自己距离远的,到能够到达的最大距离之间的加油站,看他们的油价。如果找到了更低价格的油价,就加油到刚好能到达那个加油站的距离的油,然后去那个更低价格的加油站。如果找不到更低的,就找尽可能低的油价的加油站,在当前加油站加满油之后过去。因为想要让路程上使用的尽可能是低价的油,既然没有比当前更低价格的了,就让油箱加到最大值,这样能保证利益最大化,保证最大的距离使用的是便宜的油。但有几个要注意的地方。第一个是终点的处理。基本所有的解答都是将终点当作原创 2022-02-08 11:12:44 · 282 阅读 · 0 评论 -
1059 Prime Factors -----21分
#include<iostream>#include<cmath>#include<map>#include<set>using namespace std;bool isprime(long long num){ for(long long i=2;i<=sqrt(num);i++) if(num%i==0) return false; return true;}int main(){ lo原创 2022-02-07 23:14:06 · 322 阅读 · 0 评论 -
1073 Scientific Notation (20 分)
#include<iostream>#include<string>#include<cstring>using namespace std;int main(){ string s1,s2; cin>>s1; int epoint; for(int i=0;i<s1.length();i++) { if(s1[i]=='E') { epoint=原创 2022-02-05 15:15:20 · 411 阅读 · 0 评论 -
1050 String Subtraction (20 分)
题目大意:给出两个字符串,在第一个字符串中删除第二个字符串中出现过的所有字符并输出分析:用flag[256]数组变量标记str2出现过的字符为true,输出str1的时候根据flag[str1[i]]是否为true,如果是true就不输出注意:使用int lens1 = strlen(s1);int lens2 = strlen(s2);的形式,否则直接放在for循环里面会超时#include<iostream>#include<string>#include<cst原创 2022-01-29 20:49:46 · 1109 阅读 · 0 评论 -
1028 List Sorting--------21分
#include<iostream>#include<algorithm>using namespace std;struct Student{ string id; string name; int score;};Student student[10020];bool cmp1(Student a,Student b){ return a.id<b.id;}bool cmp2(Student a,Stude原创 2022-01-27 20:07:36 · 775 阅读 · 0 评论 -
1078 Hashing------20分
#include<iostream>#include<cmath>using namespace std;int isprime(int n){ if(n==1) return -1; else { for(int i=2;i<=sqrt(n);i++) if(n%i==0) return -1; return 1; }}int main(){原创 2022-01-27 19:34:16 · 995 阅读 · 0 评论 -
1088 Rational Arithmetic (20 分)
最大公约数long long gcd(long long a,long long b){ return !b?a:gcd(b,a%b);}最小公倍数long long findmin(long long a,long long b){ long long temp=gcd(a,b); return a*b/temp;}原创 2022-01-26 19:20:58 · 259 阅读 · 0 评论 -
1081 Rational Sum (20 分)
#include<iostream>using namespace std;long long gcd(long long a,long long b){ return !b?a:gcd(b,a%b);}long long findmin(long long a,long long b){ long long temp=gcd(a,b); return a*b/temp;}int main(){ long long n; long原创 2022-01-26 19:18:53 · 154 阅读 · 0 评论 -
1070 Mooncake (25 分)
#include<iostream>#include<cmath>#include<algorithm>#include<iomanip>using namespace std;struct Mooncake{ float demand; float price; float xjb;};Mooncake mooncake[1005];bool cmp1(Mooncake a,Mooncake b){ re原创 2022-01-26 16:16:16 · 196 阅读 · 0 评论 -
1036 Boys vs Girls (25 分) 注意cmp
#include<iostream>#include<string>#include<cstring>#include<algorithm>#include<bits/stdc++.h>using namespace std;struct Student{ string name; string gender; //这里写string 写char都可以 string id; int grade;}st原创 2022-01-23 19:23:36 · 310 阅读 · 0 评论 -
1031 Hello World for U (20 分)
#include<iostream>#include<string>#include<vector>using namespace std;int main(){ string s; cin>>s; int n1,n2,n3,n; n=s.length()+2; if(n%3==0) n2=n/3; else if(n%3==1) n2=n/3+1; else原创 2022-01-23 11:49:52 · 228 阅读 · 0 评论 -
1027 Colors in Mars (20 分)
#include#include#includeusing namespace std;void change(int n){int m=0;vector temp;do{temp.push_back(n%13);n=n/13;}while(n!=0);char c=‘A’;if(temp.size()==1){cout<<‘0’;if(temp[0]>9)printf("%c",‘A’+temp[0]-10);elsecout<<temp原创 2022-01-23 10:14:09 · 333 阅读 · 0 评论 -
1016 Phone Bills -----15分
#include#include#includeusing namespace std;struct client{string name;int month;int day;int hour;int minute;string statue;}per[1000];int fee[24];bool cmp1(client a,client b){if(a.name!=b.name)return a.name<b.name;else if(a.month!=b.mon原创 2022-01-20 20:32:49 · 197 阅读 · 0 评论 -
1052 Linked List Sorting--------22分
#include<iostream>#include<algorithm>using namespace std;struct node{ int address; int key; int next; int exist;}nodes[100005];bool cmp1(node a,node b){ if(a.exist==0||b.exist==0) return a.exist>b.exist;原创 2022-01-20 12:14:46 · 224 阅读 · 0 评论 -
1032 Sharing-------21分
#include<iostream>#include<string>#include<map>#include<vector>using namespace std;char word[100005];int node[100005];int main(){ int firadd1,firadd2,n; cin>>firadd1>>firadd2>>n; int add,next;原创 2022-01-19 22:46:54 · 600 阅读 · 0 评论 -
1062 Talent and Virtue (25 分)
#include<iostream>#include<string>#include<algorithm>using namespace std;struct people{ string name; int talent; int virtue;};bool cmp1(people a,people b){ int totala=a.virtue+a.talent; int totalb=b.virtue+b.t原创 2022-01-19 14:58:23 · 407 阅读 · 0 评论 -
1060 Are They Equal----------19分
#include#include#includeusing namespace std;int main(){int n;cin>>n;string a,b;cin>>a>>b;vector suma;vector sumb;int kinda=0;int kindb=0;int flaga=0,flagb=0;if(a.find(".")!=string::npos){if(a[a.find(".")-1]==‘0’&&原创 2022-01-18 23:11:28 · 133 阅读 · 0 评论 -
1025 PAT Ranking (25 分)
#include<iostream>#include<algorithm>using namespace std;struct student{ int teamno; string name; int score; int scoreno; //小组排名 int totalno; //总分排名}stu[30000];bool cmp1(student a,student b){ if(a.score!=b.score)原创 2022-01-17 12:53:33 · 244 阅读 · 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 prime.Now given any two positive integers N (<105) a原创 2022-01-13 15:51:21 · 133 阅读 · 0 评论 -
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 encourage students by emphasi原创 2022-01-13 10:53:09 · 176 阅读 · 0 评论 -
1011 World Cup Betting (20 分)
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. Similarly, football betting原创 2022-01-12 16:14:28 · 173 阅读 · 0 评论 -
1096 Consecutive Factors (20 分)
1096 Consecutive Factors (20 分)Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3×5×6×7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are原创 2022-01-12 15:45:46 · 279 阅读 · 0 评论 -
1010 Radix 22分
仅22分 测试点0,7,17不能通过即上下限,大数不能通过,懒得用二分法1010 Radix (25 分)Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number.Now for any pair of positive integ原创 2022-01-12 11:10:33 · 188 阅读 · 0 评论 -
1007 Maximum Subsequence Sum (25 分)
1007 Maximum Subsequence Sum (25 分)Given a sequence of K integers { N1, N2, …, NK}. A continuous subsequence is defined to be { Ni, Ni+1, …, Nj} where 1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the lar原创 2022-01-11 20:46:49 · 64 阅读 · 0 评论 -
1008 Elevator (20 分)
1008 Elevator (20 分)The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one fl原创 2022-01-11 10:53:51 · 162 阅读 · 0 评论 -
1005 Spell It Right (20 分)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file contains one test case. Each case occupies one line which contains an N (≤10100).O原创 2022-01-11 10:53:02 · 147 阅读 · 0 评论 -
1003 Emergency (25 分)
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked原创 2022-01-10 22:11:25 · 140 阅读 · 0 评论 -
1001 A+B Format
Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Specification:Each input file contains one test case. Each case contains a pair of i原创 2022-01-10 11:57:50 · 153 阅读 · 0 评论 -
1002 A+B for Polynomials (25 分)
This time, you are supposed to find A+B where A and B are two polynomials.InputEach input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 … NK aNK, where K is the number of原创 2022-01-10 11:55:48 · 62 阅读 · 0 评论 -
1001. A+B Format (20)
Calculate a + b and output the sum in standard format — that is, the digits must be separated into groups of three by commas (unless there are less than four digits).InputEach input file contains one test case. Each case contains a pair of integers a and转载 2022-01-10 11:54:05 · 85 阅读 · 0 评论