标签:ems include 便宜 return border cell contest 题目 index
补的,不过都是自己做的。
A。Pupils Redistribution 【数学】
题意:交换A、B两数组中的元素,使得两组数组含1、2、3、4、5元素的个数相等。
做法:统计A组中1~5的个数,B组中减去。统计正数/2、负数/2绝对值,求两者最大值。数学问题,自己推一下。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include <bits/stdc++.h> #define MEM(a,b) memset(a,b,sizeof(a)) using namespace std; int main(){ int n, a[110], b[110], sco[10]; scanf ( "%d" ,&n); MEM(sco,0); for ( int i = 0; i < n; i++){ scanf ( "%d" , a + i); sco[a[i]] ++; } for ( int i = 0; i < n; i++){ scanf ( "%d" , b + i); sco[b[i]] --; } int sum1 = 0, sum2 = 0;; for ( int i = 1; i <= 5; i++){ if (sco[i] % 2 != 0){ puts ( "-1" ); return 0; } else if (sco[i] > 0){ sum1 += sco[i] >> 1; } else if (sco[i] < 0){ sum2 -= sco[i] >> 1; } } printf ( "%d\n" , max(sum1,sum2) ); } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <bits/stdc++.h> #define MEM(a,b) memset(a,b,sizeof(a)) using namespace std; int main(){ int n, k; cin >> n >> k; int ans = 0, sum = 0; if (n == 0){ cout << 0 << endl; return 0; } while (n){ if (n % 10 == 0) k--; else ans++; if (k == 0) break ; n /= 10; sum ++; } if (k == 0) cout << ans << endl; else cout << sum - 1 << endl; } |
C。Dishonest Sellers【贪心】
题意:你需要买N个商品,分别给出今天的价格和下一周的价格,你今天必须买K个。求最少花钱方案。
做法:根据A[i]-B[i]的结果sort一下(也就是今天优惠程度越高排越前)。然后从左往右先买K个A,剩下的买A、B中便宜的。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <bits/stdc++.h> using namespace std; struct Node{ int a,b; }node[200010]; bool cmp( const Node &x, const Node &y){ return x.a - x.b < y.a - y.b; } int main(){ int n, k; cin >> n >> k; for ( int i = 0; i < n; i++) cin >> node[i].a; for ( int i = 0; i < n; i++) cin >> node[i].b; sort(node, node + n, cmp); int sum = 0, i; for (i = 0; i < k; i++) sum += node[i].a; for (i; i < n; i++){ if (node[i].a < node[i].b) sum += node[i].a; else break ; } for (i; i < n; i++) sum += node[i].b; cout << sum << endl; } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include <bits/stdc++.h> using namespace std; char a[200020], b[200020]; int num[200020]; int len; bool judge( int x) { bool vis[200020]; memset (vis, false , sizeof (vis)); for ( int i = x + 1; i <= len; i++) vis[num[i]] = true ; int idx = 1; for ( int i = 1; i <= strlen (b+1); i++) { while (vis[idx] == false || a[idx] != b[i]){ idx++; if (idx > len){ return false ; } } idx++; } return true ; } int main(){ scanf ( "%s%s" ,a+1,b+1); len = strlen (a+1); for ( int i = 1; i <= len; i++) scanf ( "%d" , num + i); int low = 0, high = len - 1; while (low < high){ int mid = (low + high + 1) / 2; if (judge(mid)) low = mid; else high = mid - 1; } printf ( "%d\n" ,low); } |
Codeforces Round #402 (Div. 2)
标签:ems include 便宜 return border cell contest 题目 index
原文地址:http://www.cnblogs.com/zhwong/p/6476722.html