- 博客(65)
- 收藏
- 关注
原创 求解最大公因数+求解最小公倍数
#include<iostream>using namespace std;int gcd(int a,int b) //最大公约数{ return !b?a:gcd(b,a%b);}int lcm(int a,int b) //最小公倍数{ return a/gcd(a,b)*b/gcd(a,b);}int main(){ return 0;}
2022-02-10 14:58:22
417
原创 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
404
原创 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
原创 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
339
原创 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
91
原创 1033 To Fill or Not to Fill (25 分) 贪心算法
首先讲一下思路。这道题是一个贪心算法的题,大体方法就是0.寻找比自己距离远的,到能够到达的最大距离之间的加油站,看他们的油价。如果找到了更低价格的油价,就加油到刚好能到达那个加油站的距离的油,然后去那个更低价格的加油站。如果找不到更低的,就找尽可能低的油价的加油站,在当前加油站加满油之后过去。因为想要让路程上使用的尽可能是低价的油,既然没有比当前更低价格的了,就让油箱加到最大值,这样能保证利益最大化,保证最大的距离使用的是便宜的油。但有几个要注意的地方。第一个是终点的处理。基本所有的解答都是将终点当作
2022-02-08 11:12:44
279
原创 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
319
原创 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
406
原创 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
1106
原创 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
772
原创 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
990
原创 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
255
原创 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
149
原创 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
194
原创 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
308
原创 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
227
原创 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
331
原创 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
194
原创 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
221
原创 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
598
原创 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
原创 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
原创 全排序和N皇后
```cpp#include<iostream>#include<cstdio>using namespace std;const int maxn=11;int n,P[maxn],hashTable[maxn]={0};//P为当前排列,hashTable记录整数x是否已在P中//当前处理的事排列的第index位void generateP(int index){ if(index==n+1) //递归边界 此时已经处理完1-N位 { .
2022-01-17 15:12:46
81
原创 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
241
原创 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
132
原创 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
175
原创 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
172
原创 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
278
原创 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
原创 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
63
原创 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
161
原创 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
146
原创 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
139
原创 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
151
原创 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
61
转载 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
84
原创 1022 D进制的A+B (20分)
输入两个非负 10 进制整数 A 和 B (≤2^30−1),输出 A+B 的 D (1<D≤10)进制数。输入格式:输入在一行中依次给出 3 个整数 A、B 和 D。输出格式:输出 A+B 的 D 进制数。#include#include#include#includeusing namespace std;int main(){int a,b,d;cin>...
2020-04-22 09:11:04
239
原创 PAT 1089 狼人杀-简单版(20 分)- 乙级
这道题目不能假设i和j是说谎的人。为什么呢?因为如果根据说谎的人来给每个人判断谁是好人谁是坏人,那么没涉及到的人是好人还是坏人就没办法来判断了。如例1中;5-2+3-4+5+4就根本没涉及到1号究竟是好人还是坏人。...
2020-04-15 19:37:18
165
原创 1080 MOOC期终成绩 (25分)
作为一个菜鸡每次写完看柳婼的就更加觉得自己是个NC先上自己的脑瘫代码#include #include #include #include #include #include <unordered_map>#include#includeusing namespace std;struct stu{string name;int score;};bool...
2020-04-14 19:51:29
250
转载 1095 解码PAT准考证 (25 point(s))
自己写一半就知道肯定要超时了,直接就把柳婼的拿过来了。。。不过也算获得了一些知识吧。下面将一下比较重要的地方。这道题只有200ms,所以不能用map要用unordered_map。同时,在打印时全部要用printf,不能用cout,cout经测试会超时。比较关键的还是这句话:for(auto it:m)ans.push_back({it.first,it.second});这句话的意思...
2020-04-11 19:15:33
170
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人