其他分享
首页 > 其他分享> > 1952-分披萨-sorting,implementation

1952-分披萨-sorting,implementation

作者:互联网

 1 

 


#include<bits/stdc++.h> 2 /*第一行两个整数n,d (1≤n≤10^5,1≤d≤20),表示切披萨的刀数和小明希望的 d 的大小。 3 接下来一共 n 行,每行一个整数 wi(0≤wi≤359),表示第 i 刀切的位置。*/ 4 #define N 100005 5 int arr[N]; 6 int big[N]; 7 int cmp(const void* a, const void* b) { 8 return *(int*)a - *(int*)b; 9 } 10 int main() { 11 int n, d; 12 scanf("%d%d", &n, &d); 13 for (int i = 0; i < n; i++) { 14 scanf("%d",&arr[i]); 15 } 16 qsort(arr, n, sizeof(arr[0]), cmp); 17 18 for (int i = 1; i < n; i++) { 19 if (arr[i] - arr[i - 1] > 180) { 20 big[i - 1] = 360-arr[i] + arr[i - 1]; 21 } 22 else 23 big[i - 1] = arr[i] - arr[i - 1]; 24 25 } 26 big[n-1] = arr[n - 1] - arr[0]; 27 int max = 0; 28 for (int i = 1; i <= n; i++) { 29 if (max < big[i - 1]) max = big[i - 1]; 30 } 31 if (max < 180) max = 360 - max; 32 if (360 - d >= max) printf("YES\n"); 33 else printf("NO\n"); 34 return 0; 35 }

 

标签:arr,sorting,return,implementation,big,披萨,int,printf
来源: https://www.cnblogs.com/zrzsblog/p/15669108.html