PAT 2011 秋

A : World Cup Betting

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     double sum = 0.65, cnt = 3;
10     double tmpW, tmpT, tmpL;
11     while(cnt--)
12     {
13         cin >> tmpW >> tmpT >> tmpL;
14         if(tmpW > max(tmpT, tmpL))
15         {
16             cout << "W ";sum *= tmpW;
17         }
18         else if(tmpT > max(tmpW, tmpL))
19         {
20             cout << "T "; sum *= tmpT;
21         }
22         else
23         {
24             cout << "L "; sum *= tmpL;
25         }
26     }
27     printf("%.2f", (sum-1)*2);
28     return 0;
29 }
View Code

B:The Best Rank

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <vector>
 4 #include <string>
 5 #include <unordered_map>
 6 #include <algorithm>
 7 #include <functional>
 8 
 9 using namespace std;
10 typedef struct NODE
11 {
12     string id;
13     int math, english, cCode, aver;
14     NODE(){}
15     NODE(int m, int e, int c, int a):math(m),english(e),cCode(c),aver(a){}
16 }node;
17 vector<int> mathVec, engVec, cCodeVec, averVec;
18 unordered_map<string, node> nodeMap;
19 unordered_map<string, int> nodeFlagMap;
20 void getBestRank(string tmpStr)
21 {
22     char typeStr[]="ACME";
23     int type = 0, rank = 9999999;
24     for(int i = 0; i < averVec.size(); ++ i)
25     {
26         if(averVec[i] == nodeMap[tmpStr].aver)
27         {
28             rank = i+1;
29             break;
30         }
31     }
32     for(int i = 0; i < cCodeVec.size(); ++ i)
33     {
34         if(cCodeVec[i] == nodeMap[tmpStr].cCode && i + 1 < rank)
35         {
36             type = 1;
37             rank = i+1;
38             break;
39         }
40     }
41     for(int i = 0; i < mathVec.size(); ++ i)
42     {
43         if(mathVec[i] == nodeMap[tmpStr].math && i + 1 < rank)
44         {
45             type = 2;
46             rank = i+1;
47             break;
48         }
49     }
50     for(int i = 0; i < engVec.size(); ++ i)
51     {
52         if(engVec[i] == nodeMap[tmpStr].english && i + 1 < rank)
53         {
54             type = 3;
55             rank = i+1;
56             break;
57         }
58     }
59     printf("%d %c\n", rank, typeStr[type]);
60 }
61 int main()
62 {
63     int N, M;
64     cin >> N >> M;
65     string tmpId;
66     int tmpMath, tmpEng, tmpCode, tmpAver;
67     for(int i = 0; i < N; ++i)
68     {
69         cin >> tmpId >> tmpCode >> tmpMath >> tmpEng;
70         tmpAver = (tmpMath+tmpEng+tmpCode+1.5)/3;
71         mathVec.push_back(tmpMath);
72         cCodeVec.push_back(tmpCode);
73         engVec.push_back(tmpEng);
74         averVec.push_back(tmpAver);
75         nodeFlagMap[tmpId] = 1;
76         nodeMap[tmpId] = NODE(tmpMath, tmpEng, tmpCode, tmpAver);
77     }
78     sort(mathVec.begin(), mathVec.end(), greater<int>());
79     sort(cCodeVec.begin(), cCodeVec.end(), greater<int>());
80     sort(engVec.begin(), engVec.end(), greater<int>());
81     sort(averVec.begin(), averVec.end(), greater<int>());
82     for(int i = 0; i < M; ++ i)
83     {
84         cin >> tmpId;
85         if(nodeFlagMap[tmpId])
86             getBestRank(tmpId);
87         else
88             cout << "N/A" << endl;
89     }
90     return 0;
91 }
View Code

C: Battle Over Cities

  查连通图个数,深搜即可。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <vector>
 4 #include <cstring>
 5 #include <cstdlib>
 6 #include <string>
 7 #include <unordered_map>
 8 #include <algorithm>
 9 #include <functional>
10 
11 
12 using namespace std;
13 const int INF = 0x7f7f7f7f;
14 const int MAXCITY = 1010;
15 #define CLR(a,b) memset(a,b,sizeof(a));
16 int routeMap[MAXCITY][MAXCITY];
17 int visitFlag[MAXCITY];
18 void dfs(int u)
19 {
20     visitFlag[u] = 1;
21     for(int i = 1; i <= MAXCITY; ++ i)
22     {
23         if(visitFlag[i] == 0 && routeMap[u][i] == 0)
24         {
25             dfs(i);
26         }
27     }
28 }
29 int main()
30 {
31     int N, M, K;
32     cin >> N >> M >> K;
33     int tmpSt, tmpEnd;
34     CLR(routeMap, 0x7f);
35     for(int i = 0; i < M; ++ i)
36     {
37         cin >> tmpSt >> tmpEnd;
38         routeMap[tmpSt][tmpEnd] = 0;
39         routeMap[tmpEnd][tmpSt] = 0;
40     }
41     int targetCity;
42     for(int j = 0; j < K; ++ j)
43     {
44         cin >> targetCity;
45         int cnt = 0;
46         CLR(visitFlag, 0);
47         visitFlag[targetCity] = 1;
48         for(int i = 1; i <= N; ++ i)
49         {
50             if(visitFlag[i] == 0)
51             {
52                 cnt++;
53                 dfs(i);
54             }
55         }
56         cout << cnt-1 << endl;
57     }
58     return 0;
59 }
View Code

D :Waiting in Line

  模拟即可。

  注意:1.下班前没有被服务的输出Sorry

 

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <vector>
 4 #include <cstring>
 5 #include <cstdlib>
 6 #include <string>
 7 #include <unordered_map>
 8 #include <algorithm>
 9 #include <functional>
10 #include <queue>
11 
12 
13 using namespace std;
14 const int INF = 0x7f7f7f7f;
15 #define CLR(a,b) memset(a,b,sizeof(a));
16 typedef struct WINLINE
17 {
18     int lastTime, winId;
19     queue<int> winQue;
20 }winline;
21 typedef struct ALLQUE
22 {
23     vector<int> cusQue;
24     int index;
25     ALLQUE():index(0){}
26 }allque;
27 const int endTime = 17*60;
28 const int startTime = 8*60;
29 vector<int> cusTime(1010, 0);
30 bool cmp(winline a, winline b)
31 {
32     if(a.winQue.size() != b.winQue.size())
33         return a.winQue.size() < b.winQue.size();
34     else
35         return a.winId < b.winId;
36 }
37 
38 int main()
39 {
40     int N, M, K, Q, tmpNum;
41     allque allCustQue;
42     cin >> N >> M >> K >> Q;
43     for(int i = 0; i < K; ++ i)
44     {
45         cin >> tmpNum;
46         allCustQue.cusQue.push_back(tmpNum);
47     }
48     vector<winline> winInfo(N);
49     for(int i = 0; i < N; ++ i)
50     {
51         winInfo[i].lastTime = startTime;
52         winInfo[i].winId = i;
53     }
54     vector<int> tmpQue;
55     int maxCap = N*M, nowCap = 0;
56     for(int t = startTime; t < endTime; ++ t)
57     {
58         for(int i = 0; i < N; ++ i)
59         {
60             while(!winInfo[i].winQue.empty() && winInfo[i].winQue.front() <= t)
61             {
62                 winInfo[i].winQue.pop();
63                 nowCap --;
64             }
65         }
66         while(nowCap < maxCap)
67         {
68             sort(winInfo.begin(), winInfo.end(), cmp);
69             tmpNum = allCustQue.cusQue[allCustQue.index++] + winInfo[0].lastTime;
70             if(winInfo[0].lastTime < endTime)
71                 cusTime[allCustQue.index] = tmpNum;
72             winInfo[0].winQue.push(tmpNum);
73             winInfo[0].lastTime = tmpNum;
74             nowCap ++;
75             if(allCustQue.index >= K)
76             {
77                 t = endTime;
78                 break;
79             }
80         }
81     }
82     for(int i = 0; i < Q; ++ i)
83     {
84         cin >> tmpNum;
85         if(cusTime[tmpNum] >= startTime)
86         {
87             tmpNum = cusTime[tmpNum];
88             printf("%02d:%02d\n", tmpNum/60, tmpNum%60);
89         }
90         else
91             cout << "Sorry" << endl;
92     }
93     return 0;
94 }
View Code

 

posted on 2019-08-15 16:26  ChangeUp  阅读(155)  评论(0)    收藏  举报

导航