[关闭]
@Dmaxiya 2020-12-12T15:21:31.000000Z 字数 2467 阅读 1159

Codeforces Round #448 (Div. 2)

Codeforces


Contests 链接:Codeforces Round #448 (Div. 2)
过题数:2
排名:729/8334

A. Pizza Separation

题意

将一个披萨分成 块小扇形,每块小扇形的圆心角为 ,现在要求从这些小扇形中选出一部分连续的小扇形,要求这些连续的小扇形组成的大扇形与剩下的所有小扇形组成大扇形的圆心角和的差的绝对值最小,求最小的圆心角度差的绝对值。

输入

第一行为一个整数 ,第二行为 个整数 ,且数据保证

输出

输出答案。

样例

输入 输出 提示
4
90 90 90 90
0 第一部分可以选择第 和第 块扇形,另一部分可以选择第 和第 块扇形,
这样结果就是
3
100 100 160
40
1
360
360 由于只有一块扇形,所以只能将这块扇形分到其中一部分,另一部分无法分到扇
形,所以结果为
4
170 30 150 10
0 第一部分可以选择第 和第 块扇形,所以结果就是
。扇形的分配如图:
rVc4ns.png

题解

暴力 便利所有的区间取最小值。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cfloat>
  7. #include <cstring>
  8. #include <string>
  9. #include <vector>
  10. #include <list>
  11. #include <queue>
  12. #include <stack>
  13. #include <map>
  14. #include <set>
  15. #include <algorithm>
  16. using namespace std;
  17. #define LL long long
  18. const int maxn = 400;
  19. int n;
  20. int num[maxn];
  21. int main() {
  22. #ifdef Dmaxiya
  23. freopen("test.txt", "r", stdin);
  24. #endif // Dmaxiya
  25. ios::sync_with_stdio(false);
  26. while(scanf("%d", &n) != EOF) {
  27. for(int i = 1; i <= n; ++i) {
  28. scanf("%d", &num[i]);
  29. }
  30. int ans = 1000;
  31. for(int i = 1; i <= n; ++i) {
  32. int tmp = 0;
  33. for(int j = i; j <= n; ++j) {
  34. tmp += num[j];
  35. ans = min(ans, abs(tmp - (360 - tmp)));
  36. }
  37. }
  38. printf("%d\n", ans);
  39. }
  40. return 0;
  41. }

B. XK Segments

题意

在一个长度为 的序列 中,找到所有的有序对 ,要求 满足 ,在区间 内恰好有 个整数能整除 ,问有多少个有序对满足条件。

输入

第一行为三个整数 ,第二行为 个整数

输出

输出满足条件的有序对的个数。

样例

输入 输出 提示
4 2 1
1 3 5 7
3 只有 是满足条件的。
4 2 0
5 3 1 7
4 满足条件的有序对是:
5 3 1
3 3 3 3 3
25 所有区间都是满足条件的,因此答案为

题解

先将整个数组排序,枚举起点 ,二分查找第一个大于等于 的整数位置 ,以及第一个大于等于 的整数的位置 ,则所有以 为起点的满足条件的有序对的个数为 。最后注意特判 的情况。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cfloat>
  7. #include <cstring>
  8. #include <string>
  9. #include <vector>
  10. #include <list>
  11. #include <queue>
  12. #include <stack>
  13. #include <map>
  14. #include <set>
  15. #include <algorithm>
  16. using namespace std;
  17. #define LL long long
  18. const int maxn = 100000 + 100;
  19. int n;
  20. LL x, k, ans;
  21. LL num[maxn];
  22. LL *itl, *itr;
  23. int main() {
  24. #ifdef Dmaxiya
  25. freopen("test.txt", "r", stdin);
  26. #endif // Dmaxiya
  27. ios::sync_with_stdio(false);
  28. while(scanf("%d%I64d%I64d", &n, &x, &k) != EOF) {
  29. ans = 0;
  30. for(int i = 0; i < n; ++i) {
  31. scanf("%I64d", &num[i]);
  32. }
  33. sort(num, num + n);
  34. for(int i = 0; i < n; ++i) {
  35. LL l = (num[i] + x - 1) / x * x + (k - 1) * x;
  36. LL r = (num[i] + x - 1) / x * x + k * x;
  37. if(k == 0) {
  38. l = num[i];
  39. r = (num[i] + x - 1) / x * x;
  40. }
  41. itl = lower_bound(num, num + n, l);
  42. itr = lower_bound(num, num + n, r);
  43. ans += itr - itl;
  44. }
  45. printf("%I64d\n", ans);
  46. }
  47. return 0;
  48. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注