Codeforces Round #582 (Div. 3)
生活随笔
收集整理的這篇文章主要介紹了
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 CodeB:
題意:給出每天的價格,如果后面天數有價格比當前天數價格低,就認為這一天為“壞”的一天,問總共有多少天是“壞的”
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 CodeC:
題意:輸入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 CodeD1:
題意:給定一些數,數能變成 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
總結
以上是生活随笔為你收集整理的Codeforces Round #582 (Div. 3)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 注意!毕业后这些专业就业难,IT相关专业
- 下一篇: 前端大神的离逝,让我们不得不有所反思。