@Dmaxiya
2020-12-12T07:21:31.000000Z
字数 2467
阅读 1456
Codeforces
Contests 链接:Codeforces Round #448 (Div. 2)
过题数:2
排名:729/8334
将一个披萨分成 块小扇形,每块小扇形的圆心角为 ,现在要求从这些小扇形中选出一部分连续的小扇形,要求这些连续的小扇形组成的大扇形与剩下的所有小扇形组成大扇形的圆心角和的差的绝对值最小,求最小的圆心角度差的绝对值。
第一行为一个整数 ,第二行为 个整数 ,且数据保证 。
输出答案。
| 输入 | 输出 | 提示 |
|---|---|---|
| 4 90 90 90 90 |
0 | 第一部分可以选择第 和第 块扇形,另一部分可以选择第 和第 块扇形, 这样结果就是 。 |
| 3 100 100 160 |
40 | |
| 1 360 |
360 | 由于只有一块扇形,所以只能将这块扇形分到其中一部分,另一部分无法分到扇 形,所以结果为 。 |
| 4 170 30 150 10 |
0 | 第一部分可以选择第 和第 块扇形,所以结果就是 。扇形的分配如图: ![]() |
暴力 便利所有的区间取最小值。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cfloat>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <algorithm>using namespace std;#define LL long longconst int maxn = 400;int n;int num[maxn];int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyaios::sync_with_stdio(false);while(scanf("%d", &n) != EOF) {for(int i = 1; i <= n; ++i) {scanf("%d", &num[i]);}int ans = 1000;for(int i = 1; i <= n; ++i) {int tmp = 0;for(int j = i; j <= n; ++j) {tmp += num[j];ans = min(ans, abs(tmp - (360 - tmp)));}}printf("%d\n", ans);}return 0;}
在一个长度为 的序列 中,找到所有的有序对 ,要求 满足 ,在区间 内恰好有 个整数能整除 ,问有多少个有序对满足条件。
第一行为三个整数 ,第二行为 个整数 。
输出满足条件的有序对的个数。
| 输入 | 输出 | 提示 |
|---|---|---|
| 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 | 所有区间都是满足条件的,因此答案为 。 |
先将整个数组排序,枚举起点 ,二分查找第一个大于等于 的整数位置 ,以及第一个大于等于 的整数的位置 ,则所有以 为起点的满足条件的有序对的个数为 。最后注意特判 的情况。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cfloat>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <algorithm>using namespace std;#define LL long longconst int maxn = 100000 + 100;int n;LL x, k, ans;LL num[maxn];LL *itl, *itr;int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyaios::sync_with_stdio(false);while(scanf("%d%I64d%I64d", &n, &x, &k) != EOF) {ans = 0;for(int i = 0; i < n; ++i) {scanf("%I64d", &num[i]);}sort(num, num + n);for(int i = 0; i < n; ++i) {LL l = (num[i] + x - 1) / x * x + (k - 1) * x;LL r = (num[i] + x - 1) / x * x + k * x;if(k == 0) {l = num[i];r = (num[i] + x - 1) / x * x;}itl = lower_bound(num, num + n, l);itr = lower_bound(num, num + n, r);ans += itr - itl;}printf("%I64d\n", ans);}return 0;}

