pat advanced level 02-18
Posted wifepi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pat advanced level 02-18相关的知识,希望对你有一定的参考价值。
1011 World Cup Betting (20分)
#include <bits/stdc++.h> using namespace std; double a, b, c ; double MAX = -1.0, tot = 1.0 ; int main(int argc, char const *argv[]) { for(int i = 1 ; i <= 3 ; ++ i) { MAX = -1.0 ; scanf("%lf %lf %lf",&a,&b,&c); MAX = max(a, max(b,c)) ; if(MAX == a) printf("W ") ; if(MAX == b) printf("T ") ; if(MAX == c) printf("L ") ; tot *= MAX ; } printf("%.2f ",(tot*0.65 - 1) * 2) ; return 0; }
1012 The Best Rank (25分)
#include <bits/stdc++.h> using namespace std; const int inf = INT_MAX ; int n, m ; struct Student { int name ; int c, math, english ; double average ; char min_n ; int min_p ; }student[2020] ; int main(int argc, char const *argv[]) { scanf("%d %d",&n,&m) ; for(int i = 1 ; i <= n ; ++ i) scanf("%d %d %d %d",&student[i].name,&student[i].c,&student[i].math,&student[i].english), student[i].average = 1.0*(student[i].c + student[i].math + student[i].english) / 3.0 ; for(int i = 1 ; i <= n ; ++ i) { int MIN = inf ; int cnt_c = 1, cnt_m = 1, cnt_e = 1, cnt_a = 1 ; for(int j = 1 ; j <= n ; ++ j) { if(i == j) continue ; if(student[i].c < student[j].c) cnt_c ++ ; if(student[i].math < student[j].math) cnt_m ++ ; if(student[i].english < student[j].english) cnt_e ++ ; if(student[i].average < student[j].average) cnt_a ++ ; } MIN = min(cnt_a, min(cnt_c, min(cnt_m, cnt_e))) ; if(MIN == cnt_a) student[i].min_p = cnt_a, student[i].min_n = ‘A‘ ; else if(MIN == cnt_c) student[i].min_p = cnt_c, student[i].min_n = ‘C‘ ; else if(MIN == cnt_m) student[i].min_p = cnt_m, student[i].min_n = ‘M‘ ; else if(MIN == cnt_e) student[i].min_p = cnt_e, student[i].min_n = ‘E‘ ; } int tmp_name ; for(int i = 1 ; i <= m ; ++ i) { bool flag = true ; scanf("%d",&tmp_name) ; for(int j = 1 ; j <= n ; ++ j) if(student[j].name == tmp_name) flag = false, printf("%d %c ",student[j].min_p,student[j].min_n) ; if(flag) printf("N/A ") ; } return 0; }
1013 Battle Over Cities (25分)
#include <bits/stdc++.h> using namespace std; int n, m , k, destory, cnt = 0, ans = 0, head[1010] ; int mp[1010][1010] ; bool vis[1010] ; struct Edge { int to, next ; }edge[1000100] ; void addedge(int from, int to) {edge[++ ans].to = to, edge[ans].next = head[from], head[from] = ans ;} void bfs(int s) { queue<int> q ; while(!q.empty()) q.pop() ; q.push(s) ; vis[s] = true ; while(!q.empty()) { int x = q.front() ; q.pop() ; for(int i = head[x] ; ~i ; i = edge[i].next) { int to = edge[i].to ; if(vis[to] == false) vis[to] = true, q.push(to) ; } } } int main(int argc, char const *argv[]) { map<int, int> mmp ; mmp.clear() ; scanf("%d %d %d",&n,&m,&k) ; memset(mp,0,sizeof mp) ; memset(head,-1,sizeof head) ; ans = 0 ; for(int i = 1, from, to ; i <= m ; ++ i) scanf("%d %d",&from,&to), addedge(from,to), addedge(to,from) ; for(int i = 1 ; i <= k ; ++ i) { cnt = 0 ; scanf("%d",&destory) ; if(mmp[destory] != 0) {printf("%d ",mmp[destory]) ; continue ;} memset(vis,false,sizeof vis) ; vis[destory] = true ; for(int j = 1 ; j <= n ; ++ j) if(vis[j] == false) bfs(j), cnt ++ ; mmp[destory] = cnt - 1 ; printf("%d ",cnt - 1) ; } return 0; }
1015 Reversible Primes (20分)
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10 ; bool isPrime[maxn] ; int tmp[20] ; int n, d ; void primes() { memset(isPrime,false,sizeof isPrime) ; isPrime[0] = true, isPrime[1] = true ; for(int i = 2 ; i <= maxn ; ++ i) { if(isPrime[i]) continue ; for(int j = i ; j <= maxn/i ; ++ j) isPrime[i * j] = true ; } } int main(int argc, char const *argv[]) { primes() ; while(scanf("%d",&n) != EOF) { int cnt = 0 ; if(n < 0) break ; scanf("%d",&d) ; if(isPrime[n]) {printf("No ") ; continue ;} while(n) tmp[++ cnt] = n % d, n /= d ; int rev = 0 ; for(int i = 1 ; i <= cnt ; ++ i) rev = rev * d + tmp[i] ; if(isPrime[rev]) printf("No ") ; else printf("Yes ") ; } return 0; }
1017 Queueing at Bank (25分)
#include <bits/stdc++.h> using namespace std; const int inf = INT_MAX ; int n, k, cnt = 0, tot = 0 ; int h, m, s, ser ; int Wind[110] ; struct Time { int arr, ser ; bool operator < (const Time &x) const {return arr < x.arr ;} }arr[10010] ; int main(int argc, char const *argv[]) { cnt = 0 ; scanf("%d %d",&n,&k) ; for(int i = 1 ; i <= k ; ++ i) Wind[i] = 28800 ; for(int i = 1 ; i <= n ; ++ i) { tot = 0, scanf("%d:%d:%d %d",&h,&m,&s,&ser), tot = h * 3600 + m * 60 + s ; if(tot <= 61200) arr[cnt].arr = tot, arr[cnt].ser = ser * 60, ++ cnt ; } if(cnt == 0) { printf("0.0 ") ; return 0 ; } sort(arr,arr+cnt) ; tot = 0 ; for(int i = 0 ; i < cnt ; ++ i) { int ans = 0 ; int MIN = inf ; int pos = -1 ; for(int j = 1 ; j <= k ; ++ j) if(Wind[j] < MIN) MIN = Wind[j], pos = j ; if(arr[i].arr >= Wind[pos]) Wind[pos] = arr[i].arr + arr[i].ser ; else tot += Wind[pos] - arr[i].arr, Wind[pos] += arr[i].ser ; } printf("%.1lf ",tot * 1.0 / 60 / cnt) ; return 0; }
1019 General Palindromic Number (20分)
#include <bits/stdc++.h> using namespace std; int n, b, cnt = 0, m ; bool flag = true ; int tmp[50] ; int main(int argc, char const *argv[]) { scanf("%d %d",&n,&b) ; m = n ; flag = true ; while(n) tmp[++ cnt] = n % b, n /= b ; for(int i = 1 ; i <= cnt ; ++ i) if(tmp[i] != tmp[cnt - i + 1]) {printf("No ") ; for(int j = cnt ; j >= 1 ; -- j) printf("%d%c",tmp[j]," "[j == 1]) ; return 0 ;} printf("Yes ") ; for(int j = cnt ; j >= 1 ; -- j) printf("%d%c",tmp[j]," "[j == 1]) ; return 0; }
以上是关于pat advanced level 02-18的主要内容,如果未能解决你的问题,请参考以下文章