Codeforces Round #577 (Div. 2)
手速场。
题目链接:http://codeforces.com/contest/1201
A:
按题意模拟就完事了。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 int n, m; 21 string s[1010]; 22 int a[1010]; 23 ll ans = 0; 24 25 int main() { 26 cin >> n >> m; 27 for (int i = 1; i <= n; i++) cin >> s[i]; 28 for (int i = 1; i <= m; i++) cin >> a[i]; 29 for (int j = 0; j < m; j++) { 30 int maxx = 0; map<char, int>m; 31 for (int i = 1; i <= n; i++) maxx = max(maxx, ++m[s[i][j]]); 32 ans += (ll)maxx * a[j + 1]; 33 } 34 printf("%lld\n", ans); 35 return 0; 36 }
B:
检查所有元素的和是否为奇数,若为奇数则NO。
若最大元素大于和的一半,也为NO。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 int x, n, maxx = 0; 21 ll sum = 0; 22 23 int main() { 24 scanf("%d", &n); 25 rep1(i, 1, n) { 26 int x; scanf("%d", &x); 27 maxx = max(maxx, x); 28 sum += x; 29 } 30 if (sum < maxx * 2 || sum & 1) puts("NO"); 31 else puts("YES"); 32 return 0; 33 }
C:
直接从n/2+1这个位置往后填就可以了。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson (curpos<<1) 15 #define rson (curpos<<1|1) 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 2e5 + 10; 21 ll n, k, a[maxn]; 22 23 int main() { 24 scanf("%lld%lld", &n, &k); 25 rep1(i, 1, n) scanf("%lld", &a[i]); 26 sot(a, n); 27 int cnt = 1; 28 for (int i = n / 2 + 1; i < n; i++) { 29 if (k / cnt >= a[i + 1] - a[i]) { 30 k -= (a[i + 1] - a[i]) * cnt; 31 cnt++; 32 } else return printf("%lld\n", a[i] + k / cnt), 0; 33 } 34 printf("%lld\n", a[n] + k / (n / 2 + 1)); 35 return 0; 36 }