![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
coding
文章平均质量分 65
shunbenben
这个作者很懒,什么都没留下…
展开
-
PAT (Basic Level) Practise
题目集:pat.zju.edu.cn/contests/pat-b-practise B1001 #include using namespace std; int mainB1001() { int a; int count=0; cin>>a; while(1) { //cout<<count<<endl; if(a==1) break; else原创 2013-07-17 15:44:08 · 599 阅读 · 0 评论 -
1022. Digital Library (30) @ PAT (Advanced Level) Practise
考察倒排索引 #include #include #include #include #include #include using namespace std; int main() { int n; while(scanf("%d",&n)!=EOF) { //build map map> queryMap[5]; while(n--) { getchar(转载 2013-08-28 13:37:25 · 486 阅读 · 0 评论 -
1023. Have Fun with Numbers (20) @ PAT (Advanced Level) Practise
水题,这个数用字符串表示,在模拟*2 #include #include #include #include #include using namespace std; map dm; map im; string n1; vector n2,n3; void printN2() { vector::iterator it; for(it=n3.begin();it!=n3.end();it原创 2013-08-28 14:43:22 · 577 阅读 · 0 评论 -
1024. Palindromic Number (25) @ PAT (Advanced Level) Practise
Version 2: 模拟加法(http://blog.csdn.net/yhhhyfyy/article/details/8594868) #include #include #include //reverse函数用到 using namespace std; string add(strings1,string s2) { stringresult="原创 2013-08-30 14:00:57 · 482 阅读 · 0 评论 -
1025. PAT Ranking (25) @ PAT (Advanced Level) Practise
#include #include #include #include using namespace std; struct Record { string id; int mark; int local; int frank; int lrank; bool operator <(const Record & r) const { if(mark!=r.mark) {原创 2013-08-30 16:24:49 · 417 阅读 · 0 评论 -
1026. Table Tennis (30) @ PAT (Advanced Level) Practise
附AC的链接 http://blog.csdn.net/ryvipa/article/details/8584282 26分,有2个case答案错误 #include #include #include #include using namespace std; int N,K,M; int lfh,lfm,lfs; struct Table { int h,m,s; b原创 2013-09-07 14:40:20 · 558 阅读 · 0 评论 -
1027. Colors in Mars (20) @ PAT (Advanced Level) Practise
水题 #include #include using namespace std; vector transfer(int i) { int tmp; vector result; while(i>12) { tmp=i%13; result.push_back(tmp>9?('A'+tmp-10):('0'+tmp)); i/=13; } result.push_ba原创 2013-09-07 15:16:47 · 521 阅读 · 0 评论 -
1028. List Sorting (25) @ PAT (Advanced Level) Practise
水题,注意点:1 我用iostream会有一个case超时 2 id要用char * 而不是用int,不知道为什么~ #include #include #include #include using namespace std; struct Record { char id[7]; char name[8]; int mark; }; bool cmp原创 2013-09-07 20:35:27 · 531 阅读 · 0 评论 -
1029. Median (25) @ PAT (Advanced Level) Practise
这题还算简单,很明显是用归并排序,其它排序可能会超时,另外,要用stdio,不然也会超时。还有就是注意是long,int会产生错误 。 #include #include using namespace std; int main() { long N,M,m; vector v1,v2; scanf("%ld",&N); v1.resize(N); f原创 2013-09-08 09:31:32 · 440 阅读 · 0 评论 -
递归实现汉诺塔
递归 #include using namespace std; class Hanoi { public: Hanoi(int i):totalDisks(i){}; void solve(); private: int totalDisks; void moveOne(int diskID,int from,int to); void move(int diskNums,int原创 2013-08-28 10:27:14 · 461 阅读 · 0 评论 -
1021. Deepest Root (25) @ PAT (Advanced Level) Practise
思路: 这题不难,主要就是深度优先搜索DFS算法。从每个点形如进行DFS,如果一次DFS后没有全部访问到,则用DFS0(简化版)遍历全部节点,并计算连通分量(components);如果全访问到了,记录maxDepth,并从下一个点开始继续DFS。 不过这题应该有什么优化方法吧,尽管没什么优化就AC了。 #include #include #include using nam原创 2013-08-25 11:23:56 · 422 阅读 · 0 评论 -
1020. Tree Traversals (25) @ PAT (Advanced Level) Practise
思路: 对后序遍历结果从后向前进行遍历,其中每个值都是一个子树的根节点。用findNode(我用前序遍历)在tree中找到这个Node,将这个Node内的向量vct(中序遍历信息)拆分成左和右子树。 例: Sample Input: 7 2 3 1 5 7 6 4 1 2 3 4 5 6 7 Sample Output: 4 1 6 3 5 7 2 #include原创 2013-08-24 21:11:15 · 465 阅读 · 0 评论 -
1012. The Best Rank @ PAT (Advanced Level) Practise
#include #include #include #include using namespace std; bool myCmp(const int a,const int b) { return a>b; } int main() { int br; char brc; int idx; string sn; int iC,iM,iE,iA; vector name; v原创 2013-07-19 13:52:44 · 506 阅读 · 0 评论 -
1013. Battle Over Cities @ PAT (Advanced Level) Practise
#include using namespace std; struct edge { int start; int end; }; int father[1000]; edge eg[1000000]; int num; int findFather(int a) { if(!father[a]) return a; return father[原创 2013-07-19 16:59:15 · 396 阅读 · 0 评论 -
1015. Reversible Primes (20) @ PAT (Advanced Level) Practise
#include #include using namespace std; int reverse_num(int n,int d) { int x=0; while(n>=d) { x=x*d+n%d; n/=d; } x=x*d+n; return x; } bool isPrime(int num) { if (num <= 2) {原创 2013-07-29 12:04:29 · 426 阅读 · 0 评论 -
1016. Phone Bills (25) @ PAT (Advanced Level) Practise
自己写的只得了19分,还有6分的case没有通过。 附个人家的链接:http://blog.csdn.net/sunbaigui/article/details/8657062 #include #include #include #include #include #include #include using namespace std; int cpm[24]; //cents原创 2013-08-05 10:26:45 · 458 阅读 · 0 评论 -
1014. Waiting in Line @ PAT (Advanced Level) Practise
NOTICE: 1.题目中讲的“Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output "Sorry" instead.” 其实是说开始服务时间不能超过17:00而不是服务结束时间。 2.更简原创 2013-07-28 13:02:02 · 399 阅读 · 0 评论 -
1017. Queueing at Bank (25) @ PAT (Advanced Level) Practise
用优先队列模拟银行窗口,对等待队伍用List,并进行一次排序。 但是不知道为什么总通不过分值最大的第一个case,后面的13分case倒是通过了。anyway,以后再来啃。 附AC:http://blog.csdn.net/sunbaigui/article/details/8657074 #include #include #include #include #include u原创 2013-08-07 10:14:49 · 514 阅读 · 0 评论 -
1018. Public Bike Management (30) @ PAT (Advanced Level) Practise
对Dijkstra算法的复习 #include #include using namespace std; #define INF 0x6FFFFFFF struct Edge { int v,dist; Edge(int _v,int _dist):v(_v),dist(_dist){} }; struct Node { int dist; bool visited; v原创 2013-08-21 14:23:28 · 616 阅读 · 0 评论 -
1019. General Palindromic Number (20) @ PAT (Advanced Level) Practise
[水题] #include #include using namespace std; long N; long b; vector result; void divide(long n) { if(n<b) { result.push_back(n); return; } else { result.push_back(n%b); divide(n/b); }原创 2013-08-23 15:51:02 · 485 阅读 · 0 评论 -
背包问题
01背包问题 问题描述 有N件物品和一个容量为C的背包。第i件物品的体积是c[i],价值是v[i]。求解将哪些物品装入背包可使价值总和最大。 分析 用动态规划算法,状态转移方程: dp[i][j]=max{dp[i-1][j],dp[i-1][j-c[i]]+v[i]} 其中,dp[i-1][j]表示第i件物品不装入背包中,而dp[i-1][j-c[i]]+v[i]表示第原创 2013-10-09 11:08:17 · 449 阅读 · 0 评论