第二届全国中医药院校程序设计竞赛

时间:2019-10-20
本文章向大家介绍第二届全国中医药院校程序设计竞赛,主要包括第二届全国中医药院校程序设计竞赛使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
Problem  A 篮球队选拔 排序 
Problem  B 不存在的泳池 水题
Problem  C 调酒壶里的酸奶 深搜
Problem  D 过分的谜题 模拟
Problem  E 小C的数学问题 单调栈 
Problem  F fps游戏 数学题
Problem  G 闪闪发光 水题 
Problem  H 流连人间的苏苏 水题 
Problem  I 奔赴云南 水题 
Problem  J TCMPC进阶之路 水题 
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 200005;
 5 int a[maxn], b[maxn], c[maxn];
 6 int main() {
 7     int t; scanf("%d",&t);
 8     while (t--) {
 9         int n; scanf("%d",&n);
10         for (int i = 1; i <= 2*n; i++) scanf("%d",&a[i]);
11         for (int i = 1; i <= 2*n; i++) scanf("%d",&b[i]);
12         for (int i = 1; i <= 2*n; i++) c[i] = a[i]+b[i];
13         sort(c+1,c+1+2*n);
14         if (c[n] < c[n+1]) printf("Cheat\n");
15         else printf("Fail\n");
16     }
17     return 0;
18 }
Problem A 篮球队选拔
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main() {
 4     int a, b;
 5     while (~scanf("%d%d",&a,&b)) {
 6         int a2, a3, b2, b3, tmp;
 7         a2 = a3 = b2 = b3 = 0;
 8         tmp = a;
 9         while (tmp % 2 == 0) tmp /= 2, a2++;
10         tmp = a;
11         while (tmp % 3 == 0) tmp /= 3, a3++;
12         tmp = b;
13         while (tmp % 2 == 0) tmp /= 2, b2++;
14         tmp = b;
15         while (tmp % 3 == 0) tmp /= 3, b3++;
16         if (a2 > b2)
17             for (int i = 1; i <= a2-b2; i++) a /= 2;
18         else if (b2 > a2)
19             for (int i = 1; i <= b2-a2; i++) b /= 2;
20         if (a3 > b3)
21             for (int i = 1; i <= a3-b3; i++) a /= 3;
22         else if (b3 > a3)
23             for (int i = 1; i <= b3-a3; i++) b /= 3;
24         if (a != b) puts("-1");
25         else printf("%d\n",abs(a2-b2)+abs(a3-b3));
26     }
27     return 0;
28 }
Problem B 不存在的泳池
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int a, b, c, ans;
 4 const int inf = 0x3f3f3f3f;
 5 bool vis[105][105];
 6 void dfs(int na, int nb, int cur) {
 7     if (vis[na][nb]) return;
 8     if (cur > ans) return;
 9     if (na == c || nb == c) {
10         ans = min(ans,cur);
11         return;
12     }
13     vis[na][nb] = true;
14     dfs(a,nb,cur+1);
15     dfs(na,b,cur+1);
16     dfs(0,nb,cur+1);
17     dfs(na,0,cur+1);
18     dfs(max(0,na-(b-nb)),min(b,na+nb),cur+1);
19     dfs(min(a,nb+na),max(0,nb-(a-na)),cur+1);
20     vis[na][nb] = false;
21 }
22 int main() {
23     while (scanf("%d%d%d",&a,&b,&c) != EOF) {
24         if (c%__gcd(a,b) != 0) {
25             puts("impossible");
26             continue;
27         }
28         memset(vis,0,sizeof(vis));
29         ans = inf;
30         dfs(0,0,0);
31         printf("%d\n",ans);
32     }
33     return 0;
34 }
Problem C 调酒壶里的酸奶
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int a[10005];
 4 void get(int n) {
 5     int pos = 1; pos += 1;
 6     int ans = 1;
 7     while (pos != 1) {
 8         if (pos <= n) pos += pos, ans++;
 9         else pos -= 2*n-pos+1, ans++;
10     }
11     a[n] = ans;
12 }
13 int main() {
14     for (int i = 1; i <= 10000; i++)
15         get(i);
16     int n;
17     while (scanf("%d",&n) != EOF) {
18         printf("%d\n",a[n]);
19     }
20     return 0;
21 }
Problem D 过分的谜题
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 1e5+5;
 5 ll a[maxn], sum[maxn];
 6 int L[maxn], R[maxn];
 7 int main() {
 8     int n; scanf("%d",&n);
 9     for (int i = 1; i <= n; i++) {
10         scanf("%lld",&a[i]);
11         sum[i] = sum[i-1]+a[i];
12     }
13     for (int i = 1; i <= n; i++) {
14         int l = i;
15         while (a[i] <= a[l-1] && l > 1) l = L[l-1];
16         L[i] = l;
17     }
18     for (int i = n; i >= 1; i--) {
19         int r = i;
20         while (a[i] <= a[r+1] && r < n) r = R[r+1];
21         R[i] = r;
22     }
23     ll ans = -1;
24     int l, r;
25     for (int i = 1; i <= n; i++) {
26         ll val =  (sum[R[i]]-sum[L[i]-1])*a[i];
27         if (ans < val) {
28             ans = val;
29             l = L[i];
30             r = R[i];
31         }
32     }
33     printf("%lld\n",ans);
34     printf("%d %d\n",l,r);
35     return 0;
36 }
Problem E 小C的数学问题
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const double pi = acos(-1);
 4 int main() {
 5     int d, r, c; double a;
 6     scanf("%d%d%d%lf",&d,&r,&c,&a);
 7     double v = atan(1.0*r/d)*180/pi;
 8     int num = v/a + 1;
 9     cout << max(0,c-num) << endl;
10     return 0;
11 }
Problem F fps游戏
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 1e6+1000;
 5 ll a[maxn];
 6 int main() {
 7     int n;
 8     while (cin >> n) {
 9         memset(a,0,sizeof(a));
10         for (int i = 1; i <= n; i++) {
11             int x; scanf("%d",&x);
12             a[x]++;
13         }
14         ll ans = 0;
15         for (int i = 0; i <= 1000500; i++) {
16             a[i+1] += a[i]/2;
17             if (a[i] % 2 == 1) ans++;
18         }
19         printf("%lld\n",ans);
20     }
21     return 0;
22 }
Problem G 闪闪发光
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 1010;
 5 int n, d;
 6 bool tree[maxn];
 7 void print() {
 8     int l = 0;
 9     vector<int> L, R;
10     for (int i = 1; i <= n+5; i++) {
11         if (tree[i] && l == 0) l = i;
12         if (!tree[i] && l != 0) {
13             L.push_back(l);
14             R.push_back(i-1);
15             l = 0;
16         }
17     }
18     printf("[%d,%d]",L[0],R[0]);
19     for (int i = 1; i < L.size(); i++)
20         printf(",[%d,%d]",L[i],R[i]);
21     printf("\n");
22 }
23 int main() {
24     scanf("%d%d",&n,&d);
25     while (d--) {
26         int l, r; scanf("%d%d",&l,&r);
27         for (int i = l; i <= r; i++) tree[i] = true;
28         print();
29     }
30     return 0;
31 }
Problem H 流连人间的苏苏
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main() {
 4     string s; int t1, t2;
 5     while (cin >> s >> t1 >> t2) {
 6         t1 = t1/100*60 + t1%100;
 7         t2 = t2/100*60 + t2%100;
 8         printf("%s to Kunming: %02d:%02d\n",s.c_str(),(t2-t1)/60,(t2-t1)%60);
 9     }
10     return 0;
11 }
Problem I 奔赴云南
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main() {
 4     int t; scanf("%d",&t);
 5     while (t--) {
 6         int n; scanf("%d",&n);
 7         printf("%d\n",n*(n+1)/2);
 8     }
 9     return 0;
10 }
Problem J TCMPC进阶之路

原文地址:https://www.cnblogs.com/wstong/p/11705932.html