来看抽象代码

B3652 [语言月赛202208] 渡荆门送别

呃呃呃,你a数组从0开始的为啥还sort(a+1,a+1+n)啊
by Xile @ 2023-10-13 21:42:17


`sort`用错了,你下标是$0$~$n-1$,你写的`sort(b+1,b+n+1)`,应该写`sort(b,b+n)`。而且以你的方法,最高应该是$b_{i-1}$。
by mian_bi_zhe_df @ 2023-10-13 21:43:48


还有数组开小了,还没开long long,见祖宗吧
by Xile @ 2023-10-13 21:44:49


@[KARA_214](/user/1040753) 祖宗:你好
by heyx0201 @ 2023-10-13 21:51:02


@[Xiie](/user/428889) 蟹蟹大佬,这就去见祖宗
by KARA_214 @ 2023-10-13 21:54:20


@[Xiie](/user/428889) ```cpp #include <bits/stdc++.h> using namespace std; long long a[1000007]; long long b[1000007]; int main(){ int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; b[i]=a[i]; }sort(b,b+n);//以便后续求最高鹅和最矮鹅 for(int i=0;i<n;i++){ cout<<abs(a[i]-b[n])<<" ";//b[n]为最高鹅 }cout<<endl; for(int i=0;i<n;i++){ cout<<a[i]-b[0]<<" ";//b[0]为最矮鹅 } return 0; } ``` 开完long long 后没RE了,全WA
by KARA_214 @ 2023-10-13 22:08:36


@[KARA_214](/user/1040753) 你数组下标从0开始,那么b的最后一位是n-1啊
by Xile @ 2023-10-14 07:30:57


@[KARA_214](/user/1040753) [AC记录](https://www.luogu.com.cn/record/129208072)
by Xile @ 2023-10-14 07:31:46


AC了AC了
by KARA_214 @ 2023-10-14 13:47:01


```cpp #include <bits/stdc++.h> using namespace std; long long a[1000007]; long long b[1000007]; int main(){ int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; b[i]=a[i]; }sort(b,b+n);//以便后续求最高鹅和最矮鹅 for(int i=0;i<n;i++){ cout<<abs(a[i]-b[n-1])<<" ";//b[n]为最高鹅 }cout<<endl; for(int i=0;i<n;i++){ cout<<a[i]-b[0]<<" ";//b[0]为最矮鹅 } return 0; } ```
by KARA_214 @ 2023-10-14 13:47:50


|