
A_PAT甲级
文章平均质量分 92
chao2016
容易干不成大业绩!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
PAT 甲级 1001. A+B Format
#include <iostream> #include <stdio.h> using namespace std;int main() { int a, b, sum; while(cin >> a >> b) { sum = a + b; if(sum < 0) { printf("-"); sum原创 2017-05-24 23:16:49 · 1879 阅读 · 0 评论 -
PAT 甲级 1013. Battle Over Cities
原题传送门 题意:从一个无向图里,取出一个顶点,至少要补几条边能够使得它联通。 思路:就相当于求它的连通分量x,需要连x-1条边。 #include <iostream> #include <string.h> #include <vector> using namespace std;const int MAX = 1000 + 5;int attack; int visit[MAX]; vect原创 2017-06-07 11:31:21 · 1744 阅读 · 0 评论 -
PAT 甲级 1014. Waiting in Line
原题传送门 队列queue的应用 判断是否出队的方法:模拟时间流动,依次检查各个窗口队列 时间的处理:先用十进制,最后输出时间格式 #include<iostream> #include<queue> using namespace std;const int MAXN = 22; const int MAXK = 1000 + 5; int N, M, K, Q; // 窗口数、黄线内容量、顾客数原创 2017-06-07 15:25:54 · 1837 阅读 · 0 评论 -
PAT 甲级 1009. Product of Polynomials
原题传送门 stack和pair的使用 #include <iostream> #include <string.h> #include <stack> using namespace std; const int MAX = 2001; double input[MAX]; double result[MAX];int main(int argc, const char * argv[]) {原创 2017-06-04 09:23:38 · 1739 阅读 · 0 评论 -
PAT 甲级 1016. Phone Bills
原题传送门 题意:计算话费:先给你24小时每小时内每分钟的资费,分别是00:00-01:00,01:00-02:00的每分钟话费,单位是美分,然后给你n个电话记录,每条记录会有用户名,月:天:时:分,然后是一个状态,online表示打电话,offline表示挂电话。所以我们要排序匹配。而题目中说了保证每个人的记录是一个月份内的。 注意:如果记录on-off不能匹配的话就不计算在内。 #include原创 2017-06-09 13:02:40 · 1828 阅读 · 0 评论 -
PAT 甲级 1017. Queueing at Bank
原题传送门 题意:有N个客户,K个窗口。已知每个客户的到达时间和需要的时长(不超过60min,超过的会被压缩成60min),如果有窗口就依次过去,如果没有窗口就在黄线外等候(黄线外只有一个队伍,先来先服务),求客户的平均等待时长(十进制,单位:分钟)。银行开放时间为8点到17点,再8点之前不开门,8点之前来的人都要等待,在17点后来的人不被服务。 < algorithm >中sort()对vecto原创 2017-06-09 21:24:29 · 1817 阅读 · 0 评论 -
PAT 甲级 1018. Public Bike Management
原题传送门 此题就是理解题意很麻烦… dfs或者 dijkstra dfs: #include <iostream> #include <vector> using namespace std; const int SIZE = 501; int map[SIZE][SIZE]; struct Node{ Node(){ num =0;原创 2017-06-10 19:40:15 · 1835 阅读 · 0 评论 -
PAT 甲级 1015. Reversible Primes
原题传送门 题意:给定数10进制数N和进制D,将N转化成D进制, 再将D进制的数反转,最后转化为10进制数M,判断N和M是否都是质数。 #include <iostream> using namespace std;int isPrime(int n) { if(n < 2) return 0; for(int i = 2; i*i <= n; ++i) {原创 2017-06-08 16:14:33 · 1815 阅读 · 0 评论 -
PAT 甲级 1019. General Palindromic Number
原题传送门 进制转换 两个int数组的比较 #include <iostream> using namespace std;int b[100] = {0}; int digit_count = 0; int c[100] = {0};void Change(int n, int d) { // b[]是转化为d进制后的数的逆序 while(n) { b[digit_cou原创 2017-06-11 21:36:41 · 1726 阅读 · 0 评论 -
PAT 甲级 1020. Tree Traversals
原题传送门 树的遍历 之 已知后序和中序输出层序 #include <iostream> #include <vector> using namespace std;vector<int> post, in, level(100000, -1);void pre(int root, int start, int end, int index) { if(start > end)原创 2017-06-12 17:49:48 · 1707 阅读 · 0 评论 -
PAT 甲级 1021. Deepest Root(dfs:无向图的最远路径、连通分量个数)
原题传送门// 一次dfs可以得到从指定结点到它的最远结点的路径;可以用一个数组存储下这批最远结点 // 任取上一批中的一结点开始,第二次dfs可以得到无向图的最远路径;用另一个数组存储下这批最远结点 // 两个数组的并集就是deepest root #include <iostream> #include <vector> #include <set> using namespace std原创 2017-06-13 21:40:32 · 1856 阅读 · 0 评论 -
PAT 甲级 1012. The Best Rank
原题传送门#include <iostream> #include <map> using namespace std;const int MAX = 2001;map<string, int> query; struct node { // 按相等时的优先顺序 double a; double c; double m; double e; } grade[MAX原创 2017-06-06 20:54:15 · 1714 阅读 · 0 评论 -
PAT 甲级 1024. Palindromic Number(大整数相加的回文数字)
原题传送门 long int类型的最大值是2147483647,当一个10^10的数连续加两次就超过了范围,所以这是大整数相加问题。 对string类型翻转用reverse() // < algorithm > 注意string类型的加法 #include <iostream> #include <string> #include <algorithm> using namespace std;s原创 2017-06-16 23:17:42 · 1824 阅读 · 0 评论 -
PAT 甲级 1002. A+B for Polynomials
This time, you are supposed to find A+B where A and B are two polynomials. Input Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomi原创 2017-05-25 10:17:43 · 1713 阅读 · 0 评论 -
PAT 甲级 1003.Emergency
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 le原创 2017-05-25 15:42:02 · 1759 阅读 · 0 评论 -
PAT 甲级 1004. Counting Leaves
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. Input Each input file contains one test case. Each case starts with a line conta原创 2017-05-26 09:23:59 · 1754 阅读 · 0 评论 -
PAT 甲级 1005. Spell It Right
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 c原创 2017-05-27 09:21:17 · 1739 阅读 · 0 评论 -
PAT 甲级 1007. Maximum Subsequence Sum
原题传送门 当临时最大和temp < 0,那么后面不管来什么值,都应该舍弃temp < 0前面的内容。舍弃后,直接令temp = 0,并且同时更新left的临时值temp_left。 最大子序列中可能存在长度更小、sum相同的最大子序列,这里没有考虑。 #include <iostream> #include <vector> using namespace std;int main(int arg原创 2017-05-28 12:35:09 · 1745 阅读 · 0 评论 -
PAT 甲级 1006. Sign In and Sign Out
原题传送门 < algorithm >中的sort()用法 #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std;struct info { string ID_number; string Sign_in_time; string原创 2017-05-28 09:48:22 · 1848 阅读 · 2 评论 -
PAT 甲级 1008. Elevator
原题传送门 电梯计时问题 #include <iostream> using namespace std;int main(int argc, const char * argv[]) { int N, number0, number1, time_stop, time_total = 0; cin >> N; time_stop = 5 * N; number0 =原创 2017-05-30 14:41:40 · 1750 阅读 · 0 评论 -
PAT 甲级 1023. Have Fun with Numbers(大数的两倍运算)
原题传送门 题意:给出一个长度不超过20的整数,问这个整数两倍后的数位是否为原数位的一个排列。再输出两倍后的结果。 #include <iostream> #include <string.h> using namespace std;int book[10] = {0}; // 判定关键,若两倍后的数位为原数位的一个排列,则++ --后book[10]依然全是0int main(int argc,原创 2017-06-15 21:10:31 · 2068 阅读 · 0 评论 -
PAT 甲级 1010. Radix
原题传送门 目前来讲最难的,用到了二分思想 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; LL Map[256]; // 0~9、a~z与10~35的对应 LL inf = (1LL << 63) - 1; // long long的最大值2原创 2017-06-05 11:26:50 · 1801 阅读 · 0 评论 -
PAT 甲级 1011. World Cup Betting
原题传送门 就是找三组三个数中的最大值,按公式计算结果 注意:原题中的示例输出有误,实际AC的代码不需要将结果四舍五入的处理 代码一 #include <iostream> #include <algorithm> #include <iomanip> using namespace std;int main(int argc, const char * argv[]) { double原创 2017-06-05 12:31:54 · 2147 阅读 · 0 评论 -
PAT 甲级 1022. Digital Library(map,读取标准输入)
原题传送门 模拟数字图书馆的查询功能。会给出n本书的信息,以及m个需要查询的命令,数字标号对应相应的命令,数字编号后面的字符串是查询的搜索词,要求输出这行命令以及输出满足条件的书的id,如果一个都没有找到,输出Not Found。 #include <iostream> #include <map> #include <set> using namespace std;map<string, set原创 2017-06-14 12:22:05 · 1823 阅读 · 0 评论