pat甲级
lhfl911
这个作者很懒,什么都没留下…
展开
-
1014 Waiting in Line --队列模拟
模拟题,注意题意。。。 for those customers who cannot be served before 17:00, you must output “Sorry” instead.17点之前被接待了,服务超过17点也不要紧。#include <cstdio>#include <cstring>#include <queue>#include <algorithm>us原创 2016-11-28 20:04:04 · 226 阅读 · 0 评论 -
1021 Deepest Root --dfs
先判断是不是树,并查集和深搜都可以 求树的直径,两遍搜索,答案为其合集。#include <cstdio>#include <cstring>#include <vector>#include <set>#include <algorithm>using namespace std;const int MAXN = 10010;vector<int> mp[MAXN];bool vis原创 2016-12-04 15:09:43 · 212 阅读 · 0 评论 -
1022 Digital Library ---map+set
#include <cstdio>#include <cstring>#include <string>#include <map>#include <set>#include <iostream>#include <algorithm>using namespace std;map<string, set<int> > mp[6];int main() { string s;原创 2016-12-04 15:56:22 · 252 阅读 · 0 评论 -
1023 Have Fun with Numbers (20) --大数
#include <cstdio>#include <cstring>bool cmp(char x[], char y[], int len) { int vix[10], viy[10]; memset(vix, 0, sizeof(vix)); for (int i = 0; i < len; i++) vix[x[i]-'0']++; mem原创 2016-12-04 16:32:04 · 251 阅读 · 0 评论 -
1024 Palindromic Number (25)
大数模拟#include <cstdio>#include <cstring>#include <algorithm>using namespace std;bool pal(char a[]) { int len = strlen(a); for (int i = 0; i < len; i++) if (a[i] != a[len-1-i])原创 2016-12-04 17:23:21 · 565 阅读 · 0 评论 -
1025 PAT Ranking (25)
简单的排序#include <bits/stdc++.h>using namespace std;struct node { long long id; int score, loc, locrank, rank; friend bool operator<(const node &a, const node &b) { if (a.score == b.s原创 2016-12-04 20:21:45 · 340 阅读 · 0 评论 -
1010 Radix ---二分
这个题。。。 有毒 疯狂wa首先最大进制并不是36, 你得二分。。 其次会爆longlong。。 输出格式用lld。。。#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef unsigned long long LL;char a[20原创 2016-11-20 20:13:05 · 542 阅读 · 0 评论 -
PAT1011 World Cup Betting
水题注意浮点型精度#include <cstdio>const double eps = 1e-9;int main() { double x, sum = 1; for (int i = 0; i < 3; i++) { double max = -1e10; int mi = 0; for (int j = 1; j <= 3; j原创 2016-11-22 20:54:07 · 258 阅读 · 0 评论 -
1012 The Best Rank
成绩排序取所有科目成绩中最高的排名.开了4个数组模拟…. 注意成绩平均分四舍五入,并不能按总分排,其次成绩相等排名并排.#include <cstdio>#include <map>#include <algorithm>using namespace std;const double eps = 1e-8;const int MAXN = 2010;struct node { int原创 2016-11-25 16:46:55 · 200 阅读 · 0 评论 -
1013 Battle Over Cities --dfs找联通块
如果失去某个城市后分为k个联通块,则最少需k-1条边使其联通#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int MAXN = 1010;vector<int> mp[MAXN];bool vis[MAXN];void dfs(int i,原创 2016-11-25 18:13:54 · 285 阅读 · 0 评论 -
1027 Colors in Mars (20)
进制转换#include <cstdio>char t[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C'};void trans(int x) { printf("%c%c", t[x/13], t[x%13]);}int main() { int x, y, z; scanf("%d%d%d", &x, &y原创 2017-02-27 10:58:15 · 252 阅读 · 0 评论 -
1028 List Sorting (25)
排序#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct stu { int id; char name[10]; int grade;};const int MAXN = 1e5+5;stu s[MAXN];bool cmp1(stu a, stu b) {原创 2017-02-27 10:58:52 · 243 阅读 · 0 评论 -
PAT甲1123 Is It a Complete AVL Tree (30) --AVL
题意很简单,按avl数进行插入操作,最后进行层序遍历输出,判断是不是一个完全二叉树。还是太菜, avl没写出来。。。#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;struct node { int num, h; node *left,原创 2016-12-12 12:39:10 · 652 阅读 · 0 评论 -
1009 Product of Polynomials --多项式乘法
多项式乘法模拟,注意为0的情况下精度问题,#include <cstdio>#include <cmath>#include <vector>#include <map>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const double eps = 1e-9;vector<p原创 2016-11-19 22:24:19 · 256 阅读 · 0 评论 -
1015 Reversible Primes
素数打表,转置判断#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1e5+10;bool isprime[MAXN];void init() { memset(isprime, true, sizeof(isprime)); isprime[0原创 2016-11-28 20:31:56 · 386 阅读 · 0 评论 -
1016 Phone Bills
越做越恶心。。。 For each test case, you must print a phone bill for each customer.print for each customer 花费为0的不是顾客。。。#include <cstdio>#include <cstring>#include <string>#include <set>#include <map原创 2016-11-29 19:06:57 · 466 阅读 · 0 评论 -
1017 Queueing at Bank --队列模拟2
忘了time是关键字, 懒得改了,define一下。#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;#define time asdfastruct time { int hh, mm, ss; time() {}; time(int原创 2016-11-29 20:18:45 · 276 阅读 · 0 评论 -
1001 A+B Format
#include <cstdio>void print(int ans){ if(ans < 1000) { printf("%d", ans); return; } print(ans/1000); printf(",%03d", ans % 1000);}int main(){ int a, b; scanf("%d%d", &a, &b);原创 2016-11-19 11:18:06 · 256 阅读 · 0 评论 -
1005 Spell It Right --水
大数用字符串保存,各位求和,英文表示输出#include <cstdio>#include <cstring>char s[1000];char to[][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};void print(int x) { if (x < 10原创 2016-11-19 11:54:30 · 254 阅读 · 0 评论 -
1006 Sign In and Sign Out
两遍排序, 分别找出in最小值和out最大值#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;struct node{ char id[20]; int hh, mm, ss; friend bool operator<(const原创 2016-11-19 12:21:54 · 306 阅读 · 0 评论 -
1018 Public Bike Management --dijkstra+dfs
back不具有最优子结构,不能单纯用dijkstra解,找出所有最短可能路径dfs进行比较#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;struct node { int to, lg; node() {}; node(int t,原创 2016-12-01 20:30:44 · 296 阅读 · 0 评论 -
1019 General Palindromic Number --水题
进制转换判回文#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int num[100];int main() { int n, b; scanf("%d%d", &n, &b); if (!n) { puts("Yes"); puts("原创 2016-12-01 20:42:21 · 205 阅读 · 0 评论 -
1020 Tree Traversals --二叉树乱搞
根据后序和中序输出层次遍历的节点序#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;struct node { int l, r, il, ir; node(){} node(int ll, int rr, int ill, int ir原创 2016-12-01 21:23:34 · 461 阅读 · 0 评论 -
1007 Maximum Subsequence Sum --最大字段和
简单的dp, 但是…… 看清题意,输出的是最大子段和, 子段第一数和最后数(不是下标…)#include <cstdio>const int MAXN = 10010;int a[MAXN];int main(){ int n; scanf("%d", &n); int t, tmp, lt; int ans = -1, l, r; for(int i =原创 2016-11-19 21:02:40 · 332 阅读 · 0 评论 -
1008 Elevator
模拟#include <cstdio>int main() { int n, ans = 0; scanf("%d", &n); int l = 0, t; while (n--) { scanf("%d", &t); if (l < t) ans += 6 * (t - l); else if原创 2016-11-19 21:23:51 · 249 阅读 · 0 评论 -
1029 Median
中位数#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1e6 * 2 + 5;long long a[MAXN];int main() { int n, m; scanf("%d", &n); for (int i = 0; i < n原创 2017-02-27 11:10:45 · 438 阅读 · 0 评论