首届全国中医药院校程序设计大赛

1537 序列的混乱程度  水题 
1538 随机数 水题 
1539 完美序列 dp
1540 第k大数 二分搜索
1541 选房子 水题
1542 Game  
1543 Numbers 模拟+二进制
1544 Counting Words stringstream操作

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int inf = 0x3f3f3f3f;
 4 int main(){
 5     int t; scanf("%d",&t);
 6     while (t--) {
 7         int n; scanf("%d",&n);
 8         int mx = 0, mi = inf;
 9         while (n--) {
10             int x; scanf("%d",&x);
11             mx = max(mx,x);
12             mi = min(mi,x);
13         }
14         printf("%d\n",mx-mi);
15     }
16     return 0;
17 }
1537 序列的混乱程度

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main(){
 4     int t; scanf("%d",&t);
 5     while (t--) {
 6         int a, b; scanf("%d%d",&a,&b);
 7         printf("%d %d\n",b-a,a);
 8     }
 9     return 0;
10 }
1538 随机数

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 2005, mod = 1e9+7;
 5 int dp[maxn][maxn];
 6 int main(){
 7     for (int i = 1; i <= 2000; i++) dp[1][i] = 1;
 8     for (int i = 1; i <= 2000; i++)
 9         for (int j = 1; j <= 2000; j++)
10             for (int k = j; k <= 2000; k+=j)
11                 dp[i+1][k] = (dp[i][j]+dp[i+1][k])%mod;
12     int t; scanf("%d",&t);
13     while (t--) {
14         int n, l; scanf("%d%d",&n,&l);
15         ll ans = 0;
16         for (int i = 1; i <= n; i++)
17             ans = (ans+dp[l][i])%mod;
18         printf("%lld\n",ans);
19     }
20     return 0;
21 }
1539 完美序列

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 1e5+5;
 5 ll a[maxn], b[maxn];
 6 ll n, m, k;
 7 ll judge(ll val) {
 8     ll sum = 0;
 9     int j = 1;
10     for (int i = n; i >= 1; i--) {
11         for (; j <= m; j++) {
12             if (a[i]*b[j] >= val) {
13                 sum += m-j+1;
14                 break;
15             }
16         }
17     }
18     return sum;
19 }
20 int main() {
21     int t; scanf("%d",&t);
22     while (t--) {
23         scanf("%lld%lld%lld",&n,&m,&k);
24         for (int i = 1; i <= n; i++) scanf("%lld",&a[i]);
25         sort(a+1,a+1+n);
26         for (int i = 1; i <= m; i++) scanf("%lld",&b[i]);
27         sort(b+1,b+1+m);
28  
29         ll l = a[1]*b[1], r = a[n]*b[m];
30         ll ans;
31         while (l <= r) {
32             ll mid = (l+r)/2;
33             if (judge(mid) >= k) {
34                 ans = mid, l = mid+1;
35             }
36             else r = mid-1;
37         }
38         printf("%lld\n",ans);
39     }
40     return 0;
41 }
1540 第k大数

 

 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         int ans = 0;
 8         while (n--) {
 9             int a, b; scanf("%d%d",&a,&b);
10             if (b-a >= 2) ans++;
11         }
12         printf("%d\n",ans);
13     }
14     return 0;
15 }
1541 选房子

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 bool bit[64];
 5 bool judge(ll d) {
 6     int i = 0;
 7     while (d) {
 8         if ((d&1) == bit[i++]) return true;
 9         d >>= 1;
10     }
11     return false;
12 }
13 int main(){
14     int t; scanf("%d",&t);
15     while (t--) {
16         ll p; scanf("%lld",&p);
17         for (int i = 0; i < 64; i++) {
18             bit[i] = (p>>i)&1;
19         }
20         ll ans = 0;
21         for (ll d = 1; d <= sqrt(p); d++) {
22             if (p%d == 0) {
23                 if (judge(d)) ans++;
24                 if (d*d == p) continue;
25                 if (judge(p/d)) ans++;
26             }
27         }
28         printf("%lld\n",ans);
29     }
30     return 0;
31 }
1543 Numbers

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main() {
 4     int t; cin >> t; getchar();
 5     while (t--) {
 6         string s; getline(cin,s);
 7         stringstream ss(s);
 8         int ans = 0; string word;
 9         while (ss >> word) ans++;
10         cout << ans << endl;
11     }
12     return 0;
13 }
1544 Counting Words

 

posted @ 2019-10-18 20:00  麻辣猪仔  阅读(563)  评论(0编辑  收藏  举报