ITeye博客

风吹过PP好冷

风吹过PP好冷 · 共 39 篇文章

PAT1013 Battle Over Cities

Sample Input 3 2 3 1 2 1 3 1 2 3 Sample Output 1 0 0 #include <iostream> #include <string.h> using namespace std; int map[1000][1000]={0}; int copy_map[1000][1000]={0}; bool visit[1000]; bool need_to_check[1000]; void dfs(int n,int N) { for(int i = 1; i <= N; i++) { if(i != n && need_to_check[i] &&…

2012-11-29 23:59 · PAT · 评论(0)

PAT1003 Emergency

Sample Input 5 6 0 2 1 2 1 5 3 0 1 1 0 2 2 0 3 1 1 2 1 2 4 1 3 4 1 Sample Output 2 4 #include <iostream> using namespace std; #define INF 1000000 int Graph[500][500]; int TeamNum[500]; // 每个城市拯救队伍数目 int s[500]; // 判断是否已存入该点到S集合中 int Dist[500]; // 从v0到vi的最短路径长度 int TotalTeamNum[500]; // 从v0到k的拯救队伍数 …

2012-11-29 23:46 · PAT · 评论(0)

PAT1041 Be Unique

找出只出现过一次的数,用各种排序必然超时,需要用数组做hash表 Sample Input 1: 7 5 31 5 88 67 88 17 Sample Output 1: 31 Sample Input 2: 5 888 666 666 888 888 Sample Output 2: None #include <stdio.h> #include <stdlib.h> #define MAX 10000 #define MAX1 100000 int s[MAX] = {0},t[MAX1]; int main() { long int i; long int N; scanf("%l…

2012-11-23 23:43 · PAT · 评论(0)

PAT1042 Shuffling Machine

扑克洗牌 #include <iostream> #include <string> #include <vector> #include <iomanip> #include <map> #include <algorithm> using namespace std; void Createpoker(vector<string> &poker, string s) { for (int i = 1; i < 14; i++) { if (i > 9) { string str = s + "1"; char c = i%10 + '0'; str = str + c; poker.pu…

2012-11-23 23:42 · PAT · 评论(0)

PAT1040 Longest Symmetric String

求最长回文子串 #include <iostream> #include <string> #include <iomanip> using namespace std; int main() { string a; getline(cin,a); int max = 0; int length = a.size(); for(int i = 0; i < length; i++) { for(int j = 0; i - j >= 0 && i + j < length; j++) { if(a[i-j] != a[i+j]) { break; } if(max < 2*j + 1) { …

2012-11-23 23:41 · PAT · 评论(0)

PAT1036 Boys vs Girls

Sample Input 1: 3 Joe M Math990112 89 Mike M CS991301 100 Mary F EE990830 95 Sample Output 1: Mary EE990830 Joe Math990112 6 Sample Input 2: 1 Jean M AA980920 60 Sample Output 2: Absent Jean AA980920 NA #include <iostream> #include <iomanip> #include <string> #include <vector> using namespace std; …

2012-11-23 23:41 · PAT · 评论(0)

PAT1035 Password

Sample Input 1: 3 Team000002 Rlsp0dfa Team000003 perfectpwd Team000001 R1spOdfa Sample Output 1: 2 Team000002 RLsp%dfa Team000001 R@spodfa Sample Input 2: 1 team110 abcdefg332 Sample Output 2: There is 1 account and no account is modified Sample Input 3: 2 team110 abcdefg222 team220 abcdefg333 Samp…

2012-11-23 23:40 · PAT · 评论(0)

PAT1031 Hello World for U

Sample Input: helloworld! Sample Output: h ! e d l l lowor #include <iostream> #include <iomanip> #include <string> using namespace std; int main() { string str; cin>>str; int length = str.length(); int n1 = length/3; int n2; if (length%3 == 0) { n1--; n2 = n1 + 3; } else { n2 = n1 + length%3; } fo…

2012-11-22 23:54 · PAT · 评论(0)

PAT1029 Median

用标准库的排序全部超时,需要自己实现,另外还不能用cin cout Sample Input 4 11 12 13 14 5 9 10 15 16 17 Sample Output 13 #include <stdio.h> int N1[1000000]; int N2[1000000]; int M[2000000]; int main() { int lenN1; scanf("%d",&lenN1); for (int i = 0; i < lenN1; i++) { scanf("%d",&N1[i]); } int lenN2; scanf("%d",&lenN2); for (…

2012-11-22 23:54 · PAT · 评论(0)

PAT1028 List Sorting

用vector最后一个用例超时了。。。 Sample Input 1 3 1 000007 James 85 000010 Amy 90 000001 Zoe 60 Sample Output 1 000001 Zoe 60 000007 James 85 000010 Amy 90 Sample Input 2 4 2 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 98 Sample Output 2 000010 Amy 90 000002 James 98 000007 James 85 000001 Zoe 60 S…

2012-11-22 23:53 · PAT · 评论(0)

PAT1027 Colors in Mars

Sample Input 15 43 71 Sample Output #123456 #include <iostream> #include <iomanip> #include <string> using namespace std; void convert(int a) { int c=a/13,r=a%13; if(c==0) { if (r < 10) { printf("%d",r); } else { switch(r) { case 10: printf("A"); return; case 11: printf("B"); return; case 12: print…

2012-11-22 23:52 · PAT · 评论(0)

PAT1025 PAT Ranking

Sample Input: 2 5 1234567890001 95 1234567890005 100 1234567890003 95 1234567890002 77 1234567890004 85 4 1234567890013 65 1234567890011 25 1234567890014 100 1234567890012 85 Sample Output: 9 1234567890005 1 1 1 1234567890014 1 2 1 1234567890001 3 1 2 1234567890003 3 1 2 1234567890004 5 1 4 1234567…

2012-11-22 23:51 · PAT · 评论(0)

PAT1023 Have Fun with Numbers

大数的相加 比较两个字符串中字符完全相同 Sample Input: 1234567899 Sample Output: Yes 2469135798 #include <iostream> #include <string> #include <vector> #include <iomanip> #include <map> using namespace std; string doubleadd(string s) { int delta = 0; string result; int sum; for(int i = s.size()-1,j = s.size()-1; i>=0 …

2012-11-21 23:55 · PAT · 评论(0)

PAT1022 Digital Library

占坑。。。

2012-11-21 23:54 · 评论(0)

PAT1020 Tree Traversals

已知中序遍历 后序遍历,求层次遍历 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 <string.h> #include <iostream> using namespace std; #define MAX_TREE_SIZE 30 typedef struct BiTNode { int data; struct BiTNode *lchild,*rchild; }BiTNode,*BiTree; BiTree CreateBT(int *postorder,int *i…

2012-11-21 23:54 · PAT · 评论(0)