Codeforces Round #582 (Div. 3)

题目链接:https://codeforces.com/contest/1213


A:

题意:给定数的位置,位置为整数,每个数可以向左或右移动一格或者两格,移动一格花费一个硬币,两格不花费硬币,问所有硬币移动到同一位置至少要花费多少硬币

idea:每个数的奇偶个数

 1 #include <bits/stdc++.h>
 2  
 3 using namespace std;
 4 int a[110], n, s1, s2;
 5  
 6 int main()
 7 {
 8     cin >> n;
 9     for (int i = 0; i < n; i ++ )
10     {
11         cin >> a[i];
12         if (a[i] % 2)  s1 ++ ;  //s1为偶数 
13         else  s2 ++ ;
14     }
15     int ans = min(s1, s2);
16     cout << ans << endl;
17     return 0;
18 }
View Code

B:

题意:给出每天的价格,如果后面天数有价格比当前天数价格低,就认为这一天为“坏”的一天,问总共有多少天是“坏的”

idea:单调栈,从后面往前遍历一遍,时间复杂度O(n)

 1 #include <iostream>
 2 #include <cstdio>
 3  
 4 using namespace std;
 5 const int MAXN = 1e6 + 10;
 6 int t, n, a[MAXN];
 7  
 8 int main()
 9 {
10     cin >> t;
11     while (t -- )
12     {
13         scanf("%d",&n);
14         for (int i = 0; i < n; i ++ )
15             scanf("%d",&a[i]);
16             
17         int ss = a[n - 1], ans = 0;
18         for (int i = n - 2; i >= 0; i -- )
19         {
20             if (a[i] > ss)  ans ++ ;
21             if (a[i] < ss)  ss = a[i];
22         }
23         cout << ans << endl;
24     }
25     return 0;
26 }
View Code

C:

题意:输入n和m,求1~n中能整除m的数的个位数累加和

idea:数学题,i * m % 10 = (10 + i) * m % 10,0 <= i <= 9

 1 #include <iostream>
 2 #include <cstdio>
 3  
 4 using namespace std;
 5 typedef long long ll;
 6 int q, a[10];
 7  
 8 int main()
 9 {
10     cin >> q;
11     while (q -- )
12     {
13         ll n, m, k, sum = 0, ans = 0;
14         cin >> n >> m;
15         for (int i = 0; i < 10; i ++ )
16         {
17             a[i] = m * (1 + i) % 10;
18             sum += a[i];
19         }
20         
21         k = n / m;
22         ll s;
23         s = k % 10;
24         for (int i = 0; i < s; i ++ )  ans += a[i];
25         ans += (k / 10) * sum;
26         cout << ans << endl;
27     }
28     return 0;
29 }
View Code

D1:

题意:给定一些数,数能变成 n / 2 (向下取整),问变成某个数m,且至少有k个数能变成m需要的操作次数至少是多少

idea:记录每个数的贡献,若变成m的数大于等于k个,取前k小操作次数累加即可(纯暴力瞎搞...)

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <cstring>
 5  
 6 using namespace std;
 7 const int MAXN = 1e6;
 8 const int _inf = 0x3f3f3f;
 9 int k, n, a[MAXN], b[MAXN], c[MAXN], ans = _inf;
10  
11 int main()
12 {
13     cin >> n >> k;
14     for (int i = 0; i < n; i ++ )
15          cin >> a[i];
16          
17     int idd = 0;     
18     for (int i = 0; i < n; i ++ )
19     {
20         int x = a[i];
21         b[idd ++ ] = x;
22         while (x > 0)
23         {
24             x >>= 1;
25             b[idd ++ ] = x;
26         }
27     }
28  
29     for (int i = 0; i < idd; i ++ )
30     {
31         int id = 0;
32         for (int j = 0; j < n; j ++ )
33         {
34             int x = a[j], cur = 0;
35             while (x > b[i])
36             {
37                 x >>= 1;
38                 cur ++ ;
39             }
40             if (x == b[i]) {
41                 c[id ++ ] = cur;
42             }
43         }
44         if (id >= k) {
45             int sum = 0;
46             sort(c, c + id);
47             for (int j = 0; j < k; j ++ )   sum += c[j];
48             ans = min(ans, sum);
49         }
50         memset(c,0,sizeof c);
51     }
52     cout << ans << endl;
53     return 0;
54 }
View Code

 

PS:由于自己懒,拖了好久才补的题,以后要第一时间把题补了,专心补题

 

转载于:https://www.cnblogs.com/chuyds/p/11482320.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值