这一次的Div.2 大多数学思维。。

A. Park Lightingtime

https://codeforces.com/contest/1358/problem/A

题意:给一个n,m为边的矩形,问最少的灯使得整个矩形照亮

思路:n * m 为总区域数一个灯最多能照亮两块区域,贪心做:每次都取照亮两块

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. //freopen("in.txt","r",stdin);
  5. ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  6. int t, n, m; cin >> t;
  7. while (t--) {
  8. cin >> n >> m;
  9. cout << (n * m) / 2 + (n *m) % 2 << endl;
  10. }
  11. }

B. Maria Breaks the Self-isolation

https://codeforces.com/contest/1358/problem/B

题意:每个人有一个聚会值,要求来了的人数(算同时来的)>=聚会值,问最多能拉到多少人

思路:和之前的cfdiv2一道分配人,每个人有经验值很像,那道题是sort后从前往后尺取,这道题sort就从后往前贪心

  1. #include<iostream>
  2. #include<vector>
  3. #include<queue>
  4. #include<cstring>
  5. #include<algorithm>
  6. using namespace std;
  7. const int maxn=2e5+10;
  8. typedef long long LL;
  9. LL a[maxn];
  10. int main()
  11. {
  12. LL t;cin>>t;
  13. while(t--)
  14. {
  15. LL n;cin>>n;
  16. for(LL i=1;i<=n;i++) cin>>a[i];
  17. sort(a+1,a+1+n);
  18. if(a[n]<=n) cout<<n+1<<endl;
  19. else
  20. {
  21. LL ans=1;LL sum=0;
  22. for(LL i=n;i>=1;i--)
  23. {
  24. if(a[i]<=i)
  25. {
  26. sum+=i;break;
  27. }
  28. }
  29. cout<<sum+1<<endl;
  30. }
  31. }
  32. return 0;
  33. }

C. Celex Update

https://codeforces.com/contest/1358/problem/C

题意:求(a,b)–>(c,d)的所有路径总数中有多少路径和不同的。

思路:考虑到xy变化,移动方法一定是 (x2 - x1) * (y2 - y1) ,然后发现自己到自己也是一种 故最后+1

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. //freopen("in.txt","r",stdin);
  5. ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  6. long long x1, x2, y1, y2, t;
  7. cin >> t; while (t--) {
  8. cin >> x1 >> y1 >> x2 >> y2;
  9. cout << (x2 - x1) * (y2 - y1) + 1 << endl;
  10. }
  11. }

D. The Best Vacation

https://codeforces.com/contest/1358/problem/D

题意:每个月有d[i]天,有x天度假,要求连续,可以跨年,保证度假日子小于一整年。求d[i]求和最大的一段

思路:贪心+前缀和+二分

贪心:

有这么一段区间,贪A和贪B。

当bn(月的最后一天)>an-2,明显可以得出B是最优的。

那么当bnbn—->(等差递增)an>bn,而且a月比b月长且最大值更大,所以在a月的末尾作为最后一天最优。

所以贪心把末尾的一天放到月末。

然后我们利用前缀和统计每个月的天数和价值。然后枚举右端点,二分左端点,找到

sum[i]-sum[l]>x;且sum[i]-sum[l+1]<=x

那么价值为summoney[i]-summoney[l+1];再算多出的x部分–知道x多出有多少天,然后在多出的区间里用等差数列公式算出来。比如多出3天,就是那段区间的后三天的价值和。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 4e5 + 20;
  4. typedef long long LL;
  5. LL a[maxn];
  6. LL sumday[maxn];
  7. LL summoney[maxn];
  8. int main(void)
  9. {
  10. LL n, x; cin >> n >> x;
  11. for (LL i = 1; i <= n; i++)
  12. {
  13. cin >> a[i];
  14. sumday[i] = sumday[i - 1] + a[i];
  15. summoney[i] = summoney[i - 1] + (1 + a[i]) * a[i] / 2;
  16. }
  17. for (LL i = n + 1; i <= 2 * n; i++)
  18. {
  19. a[i] = a[i - n];
  20. sumday[i] = sumday[i - 1] + a[i];
  21. summoney[i] = summoney[i - 1] + (1 + a[i]) * a[i] / 2;
  22. }
  23. LL res = 0;
  24. for (LL i = 1; i <= 2 * n; i++)
  25. {
  26. LL l = 0; LL r = i + 1;
  27. //边界处理
  28. //找出第一个区间差大于等于x的位置
  29. while (l < r)
  30. {
  31. LL mid = (l + r) >> 1;
  32. if (sumday[i] - sumday[mid] <= x) r = mid;
  33. else l = mid + 1;
  34. }
  35. if (l == 0 || r == i + 1) continue;
  36. LL resday = x - (sumday[i] - sumday[l]);
  37. LL sum = summoney[i] - summoney[l];
  38. if (a[l] >= resday) sum += (2 * a[l] - resday + 1) * resday / 2;
  39. res = max(res, sum);
  40. }
  41. cout << res << endl;
  42. return 0;
  43. }

E、F待补。。。