原题链接:HDU5857
题意:
分析:先挂代码,分析等会写
代码:
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <algorithm> 5 6 using namespace std; 7 8 const int maxn=100010; 9 long long num[maxn]; 10 11 int main() { 12 int t; 13 scanf("%d",&t); 14 while(t--) { 15 int n,m; 16 scanf("%d%d",&n,&m); 17 for(int i=1; i<=n; i++) { 18 scanf("%I64d",&num[i]); 19 } 20 for(int i=0; i<m; i++) { 21 double ans=0; 22 int l1,r1,l2,r2; 23 scanf("%d%d%d%d",&l1,&r1,&l2,&r2); 24 if(l1>l2||(l1==l2&&r1>r2)) { 25 swap(l1,l2); 26 swap(r1,r2); 27 } 28 if(l1<=l2&&r1>=r2) { 29 swap(r1,r2); 30 } 31 int len1=r1-l1+1; 32 int len2=r2-l2+1; 33 int len=len1+len2; 34 if(r1<l2) { 35 if(len%2==0) { 36 int half=len/2; 37 if(len1>half) { 38 ans=double(num[l1+half-1]+num[l1+half])/2; 39 } else if(len2>half) { 40 ans=double(num[r2-half+1]+num[r2-half])/2; 41 } else if(len1==half) { 42 ans=double(num[r1]+num[l2])/2; 43 } 44 } else { 45 int half=len/2+1; 46 if(len1>=half) { 47 ans=double(num[l1+half-1]); 48 } else { 49 ans=double(num[r2-half+1]); 50 } 51 } 52 } else { 53 if(len%2==0) { 54 int half=len/2; 55 if(l1+half-1<l2) { 56 ans=double(num[l1+half-1]+num[l1+half])/2; 57 } else if(r2-half+1>r1) { 58 ans=double(num[r2-half+1]+num[r2-half])/2; 59 } else { 60 half=half-(l2-l1); 61 ans=double(num[l2+(int)ceil(double(half)/2)-1]+num[l2+(int)ceil(double(half+1)/2)-1])/2; 62 } 63 } else { 64 int half=len/2+1; 65 if(l1+half-1<l2) { 66 ans=double(num[l1+half-1]); 67 } else if(r2-half+1>r1) { 68 ans=double(num[r2-half+1]); 69 } else { 70 half=half-(l2-l1); 71 ans=double(num[l2+(int)ceil(double(half)/2)-1]); 72 } 73 } 74 } 75 printf("%.1f\n",ans); 76 } 77 } 78 return 0; 79 }
时间: 2025-01-14 20:36:43