自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 【CCF CSP】201312-3最大的矩形(c++)

暴力O(n²)解的有更好的方法吗?限制时间1.0s是可以运算多少次呀?基础知识欠缺#include <bits/stdc++.h>using namespace std;int main(void){ int n; scanf("%d", &n); vector<int> t(n); for(int i = 0; i < n; i++) scanf("%d", &t[i]); int max

2022-05-01 19:37:02 773

原创 【CCF CSP】201312-2 ISBN号码(c++)

简单题#include <bits/stdc++.h>using namespace std;int main(void){ string s; cin >> s; int a[15]; for(int i = 0, j = 0; i < s.size(); i++){ if(s[i] != '-') a[j++] = (int)(s[i]-'0'); } int sum =

2022-05-01 19:31:05 1065

原创 【CCF CSP】201312-1出现次数最多的数(C++)

签到题#include <bits/stdc++.h>using namespace std;int main(void){ int n; int h[10005] = {0}; //h[i]存储i出现的次数 scanf("%d", &n); for(int i = 0; i < n; i++){ int a; scanf("%d", &a); h[a]++; } i

2022-05-01 19:28:43 993

原创 PAT(A) 1014 Waiting in Line (30 point(s)) C++ 题意理解

题意理解:可看做八点前所有的顾客都已等在银行门外,排队依次进入for those customers who cannot be served before 17:00, you must output Sorry instead. 17点以前可开始被服务的输出服务结束的时间,服务结束时间可能晚于17点;17点后才轮到的输出Sorry#include<cstdio>#include<vector>#include<climits>using namespa

2021-08-27 21:37:26 95

原创 PAT(A) 1020 Tree Traversals (25 point(s)) C++ 二叉树后序中序转层序

#include <cstdio>#include <vector>#include <map>using namespace std;int N;vector<int> post, in;map<int, int> level;void dfs(int root, int left, int right, int index){ if(left > right) return; level[index] =

2021-08-22 21:10:55 75

原创 PAT(A) 1019 General Palindromic Number (20 point(s))

#include <cstdio>using namespace std;int main(){ int N, b, i, flag = 1; int a[40]; scanf("%d %d", &N, &b); for(i = 0; N != 0; i++) a[i] = N % b, N /= b; for(int j = 0; j < i; j++) if(a[

2021-08-22 21:05:07 75

原创 PAT(A) 1017 Queueing at Bank (25 point(s)) C++ 测试点0,5

注意:计算平均等待时间时应除以被银行服务的人数,而不是排队的总人数N,否则Case0:Wrong Answer银行会服务完所有17点前开始排队的顾客,而不是到17点关门,否则Case5:Wrong Answer (Case5中最晚会服务到半夜零点半左右,这什么神仙银行!#include<cstdio>#include<vector>#include<algorithm>#include<cmath>using namespace std;

2021-08-22 20:58:28 252

原创 PAT(A) 1012 The Best Rank (25 point(s)) C++测试点2

注意:Case2举例:分数:100,100,90,90,80排名:1,1,3,3,5对map的value排序:将map的key与value转为pair<key, value>存入vector,对vector使用sort排序.#include<cstdio>#include<vector>#include<map>#include<algorithm>using namespace std;struct node{

2021-08-22 10:27:11 132

原创 PAT(A) 1011 World Cup Betting (20 point(s))

#include <cstdio>int main(void){ float W, T, L, profit[3], sum; char choose[3]; for(int i = 0; i < 3; i++){ scanf("%f %f %f", &W, &T, &L); if(W > T && W > L) profit[i] = W, c

2021-08-21 22:13:59 54

原创 PAT(A) 1009 Product of Polynomials (25 point(s)) C++ 测试点0

注意:系数相加为零的要舍去,否则Case 0:Wrong Answer#include<cstdio>#include<map>using namespace std;int main(void){ int K, N; float a; map<int, float> p1, p2, m; scanf("%d", &K); for(int i = 0; i < K; i++){scanf("%d %

2021-08-21 21:33:57 157

原创 PAT(A) 1008 Elevator (20 point(s))

#include <cstdio>int main(void){ int N, floor = 0, next, sub, sum = 0; scanf("%d", &N); for(int i = 0; i < N; i++){ scanf("%d", &next); sub = next - floor; if(sub > 0) sum += 6 * sub; e

2021-08-21 21:14:44 63

原创 PAT(A) 1007 Maximum Subsequence Sum (25 point(s)) C++ 动态规划

动态规划个人理解:temp是从i开始的每个data[i]的和,把temp看做序列第一个数,若temp是负数,则舍弃,从下一个数开始重新计算temp;若temp是正数,则采用,比较记录最大的sum#include <cstdio>int main(void){ int K, data[10001], start = -1, end, sum = -1; scanf("%d", &K); for(int i = 0; i < K; i++)

2021-08-21 21:12:44 73

原创 PAT(A) 1006 Sign In and Sign Out (25 point(s)) C++

int time = hh6060 + mm*60 +ss 记录时间,便于比较#include<cstdio>#include<iostream>#include<string>using namespace std;struct node{ string id; int time;};int main(void){ int M; scanf("%d", &M); node unlocked, l

2021-08-21 20:53:47 57

原创 PAT(A) 1005 Spell It Right (20 point(s)) C++

#include <iostream>#include <string>using namespace std;int main(void){ string s1, s2; cin >> s1; char digit[10][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; int sum = 0;

2021-08-21 20:42:05 68

原创 PAT(A) 1154 Vertex Coloring (25 point(s))

储存每条边,遍历每条边判断两个顶点的颜色是否相同使用set计算颜色数#include<bits/stdc++.h>using namespace std;int N, M, K;vector<pair<int, int>> v;vector<int> color;bool judge(void){ for(int i = 0; i < M; i++) if(color[v[i].first] == color[v

2021-08-20 11:11:14 61

原创 PAT(A) 1149 Dangerous Goods Packaging (25 point(s))

#include<bits/stdc++.h>using namespace std;vector<int> icp[100010];bool judge(vector<int> v){ int n = v.size(); for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++) if(find(icp[v[i]].begin(), icp[

2021-08-19 11:14:30 63

原创 PAT(A) 1147 Heaps (30 point(s))

#include<bits/stdc++.h>using namespace std;int M, N;vector<int> v;bool isMaxHeap(void){ for(int i = 0; i <= N/2; i++){ if(2*i+1 < N) if(v[2*i+1] > v[i]) return false; if(2*i+2 < N) i

2021-08-19 09:53:28 78

原创 PAT(A) 1144 The Missing Number (20 point(s))

#include<bits/stdc++.h>using namespace std;int main(void){ int N, a; set<int> s; scanf("%d", &N); for(int i = 0; i < N; i++){ scanf("%d", &a); if(a > 0) s.insert(a); } a = 1;

2021-08-16 11:54:01 51

原创 PAT(A) 1139 First Contact (30 point(s)) 测试点

测试点2:输入存在“-0000”测试点3、4、5:AB ≠ CD#include<bits/stdc++.h>using namespace std;int N, M, K;string v1, v2;vector<int> gender;vector<vector<int>> v;map<string, int> m1; // m1: id->indexmap<int, string> m2; // m2.

2021-08-16 11:41:50 231

原创 PAT(A) 1142 Maximal Clique (25 point(s))

#include<bits/stdc++.h>using namespace std;int Nv, Ne, edge[210][210];bool isClique(vector<int> v){ int n = v.size(); for(int i = 0; i < n; i++) for(int j = i+1; j < n; j++) if(edge[v[i]][v[j]] == 0) retur

2021-08-15 18:57:44 66

原创 PAT(A) 1141 PAT Ranking of Institutions (25 point(s))

#include<bits/stdc++.h>using namespace std;struct node{ string sch; float tws = 0; int ns = 0;};bool cmp(node a, node b){ if((int)a.tws != (int)b.tws) return a.tws > b.tws; if(a.ns != b.ns) return a.ns < b.ns; retu

2021-08-15 11:27:37 77

原创 PAT(A) 1140 Look-and-say Sequence (20 point(s))

#include<bits/stdc++.h>using namespace std;int main(void){ int D, N; scanf("%d %d", &D, &N); vector<int> va, vb; va.push_back(D); for(int i = 0; i < N-1; i++){ int p1 = 0, p2 = 0; while(p1

2021-08-15 10:58:50 502

原创 PAT(A) 1138 Postorder Traversal (25 point(s))

#include<bits/stdc++.h>using namespace std;int N, post = -1;vector<int> pre, in;void dfs(int root, int beg, int en){ if(beg > en || post != -1) return; int i = beg; while(i <= en && pre[root] != in[i]) i++; d

2021-08-14 21:23:20 51

原创 PAT(A) 1137 Final Grading (25 point(s))

审题啊呜呜呜!final grade和Gfinal不是同一个东西!!!大哭.gif#include<bits/stdc++.h>using namespace std;struct node{ string id; int Gp, Gmid, Gfinal, G;};bool cmp(node a, node b){ if(a.G == b.G) return a.id < b.id; return a.G > b.G;

2021-08-14 20:55:55 77

原创 PAT(A) 1136 A Delayed Palindrome (20 point(s))

#include<bits/stdc++.h>using namespace std;string add(string sa, string sb){ string sc = ""; int n = sa.size(), tag = 0; for(int i = n-1; i >= 0; i--){ char c = sa[i] + sb[i] - '0' + tag; if(c > '9') c -= 10, tag

2021-08-14 17:37:17 73

原创 PAT(A) 1135 Is It A Red-Black Tree (30 point(s))

性质:二叉搜索树的中序遍历序列为递增序列前序+中序构建二叉搜索树审题不够细致,(4)(5)性质都是for each node#include<bits/stdc++.h>using namespace std;struct node{ int left, right, value;};int K, N;vector<node> v;vector<int> pre, in;set<int> black;bool cmp(i.

2021-08-14 09:43:42 74

原创 PAT(A) 1134 Vertex Cover (25 point(s))

#include<bits/stdc++.h>using namespace std;struct node{ int v1, v2;};int main(void){ int N, M; scanf("%d %d", &N, &M); vector<node> edge(M); for(int i = 0; i < M; i++) scanf("%d %d", &edge[i

2021-08-13 20:22:26 52

原创 PAT(A) 1133 Splitting A Linked List (25 point(s))

#include<bits/stdc++.h>using namespace std;struct node{ int add, data, next;};int main(void){ int addr, N, K; scanf("%d %d %d", &addr, &N, &K); vector<node> d(100010); for(int i = 0; i < N; i++){

2021-08-13 18:16:26 61

原创 PAT(A) 1132 Cut Integer (20 point(s))

#include<bits/stdc++.h>using namespace std;int main(void){ int N; scanf("%d", &N); for(int i = 0; i < N; i++){ long long Z, a, b, n; string s, sa, sb; scanf("%lld", &Z); s = to_string(Z);

2021-08-13 11:44:26 57

原创 PAT(A) 1130 Infix Expression (25 point(s))

#include<bits/stdc++.h>using namespace std;struct node{ string s; int left, right;};int N, root = 1;vector<node> v;void dfs(int index){ if(index == -1) return; if((v[index].left != -1 || v[index].right != -1) &&

2021-08-13 11:16:52 58

原创 PAT(A) 1099 Build A Binary Search Tree (30 point(s))

keys按升序排列,对已知结构BST填入值的过程即中序遍历#include<bits/stdc++.h>using namespace std;struct node{ int left, right, value;};int N, m = 0;vector<node> v;vector<int> key;void dfs(int index){ if(index == -1) return; dfs(v[index].lef

2021-08-12 22:22:21 60

原创 PAT(A) 1067 Sort with Swap(0, i) (25 point(s))

使用数组v[i]记录数字i的位置,降低时间复杂度#include<bits/stdc++.h>using namespace std;int main(void){ int N, x; scanf("%d", &N); vector<int> v(N); for(int i = 0; i < N; i++){ scanf("%d", &x); v[x] = i; } int

2021-08-12 10:21:22 46

原创 PAT(A) 1086 Tree Traversals Again (25 point(s))

前序中序转后序 #include<bits/stdc++.h>using namespace std;int N;vector<int> pre, in, post;void dfs(int root, int beg, int en){ if(beg > en) return; int i = beg; while(in[i] != pre[root]) i++; dfs(root+1, beg, i-1); dfs(ro

2021-08-12 08:25:17 47

原创 PAT(A) 1126 Eulerian Path (25 point(s))

#include<bits/stdc++.h>using namespace std;int N, M, cntCnn = 0, cntOdd = 0;vector<vector<int>> v;vector<int> cntDgr, vis;void dfs(int index){ vis[index] = 1; for(int i = 0; i < v[index].size(); i++) if(vis

2021-08-11 17:42:37 47

原创 PAT(A) 1125 Chain the Ropes (25 point(s))

贪心注意:The result must be rounded to the nearest integer that is no greater than the maximum length. 即向下取整见注释#include<bits/stdc++.h>using namespace std;int main(void){ int N; scanf("%d", &N); vector<float> v(N); f.

2021-08-11 11:57:24 60

原创 PAT(A) 1100 Mars Numbers (20 point(s))

#include<bits/stdc++.h>using namespace std;int main(void){ string s1[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; string s2[13] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "he

2021-08-11 11:34:38 64

原创 PAT(A) 1115 Counting Nodes in a BST (30 point(s))

#include<bits/stdc++.h>using namespace std;struct node{ int left = -1, right = -1, value, level;};int N, maxlevel = 0;vector<node> v;void buildBST(int i){ int j = 0, k, tag; while(j != -1){ k = j; if(v[i].va

2021-08-08 11:47:48 58

原创 PAT(A) 1021 Deepest Root (25 point(s))

任取一个结点作为root求出高度最大的结点,再从其中任取一个结点作为root求出高度最大的结点,两个集合求并即为the deepest root#include<bits/stdc++.h>using namespace std;int maxlevel = -1;vector<vector<int>> t;vector<int> vis, temp;set<int> root;void BFS(int index, int de

2021-08-08 09:47:13 69

原创 PAT(A) 1121 Damn Single (25 point(s))

#include<bits/stdc++.h>using namespace std;int main(void){ int N, M, a, b, c[100005], g[100005] = {0}; set<int> s; fill(c, c+100005, 100000); scanf("%d", &N); for(int i = 0; i < N; i++){ scanf("%d %d",

2021-08-07 17:38:32 65

原创 PAT(A) 1120 Friend Numbers (20 point(s))

#include<bits/stdc++.h>using namespace std;int main(void){ int N; scanf("%d", &N); set<int> id; for(int i = 0; i < N; i++){ int sum = 0; string s; cin >> s; for(int j = 0; j &

2021-08-07 17:18:09 70

空空如也

空空如也

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

TA关注的人

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