WA与AC的差距到底在哪。。。求条
  • 板块P1168 中位数
  • 楼主LeavingAC
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/8/28 22:59
  • 上次更新2024/8/28 23:04:05
查看原帖
WA与AC的差距到底在哪。。。求条
1229717
LeavingAC楼主2024/8/28 22:59
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

ll n,a[100010];

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for (ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for (ll i=1;i<=n;i++)
    {
        if (i%2==1) cout<<a[(i+1)/2]<<"\n";
    }
    return 0;
}

此代码全WA了 但理论上本代码应该与下面的AC代码实现同一功能 有没有大佬帮忙解释一下 %%%

#include <bits/stdc++.h>
using namespace std;
using ll=long long;

ll n,x;
vector<ll> v;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for (ll i=1;i<=n;i++)
    {
        cin>>x;
        v.insert(lower_bound(v.begin(),v.end(),x),x);
        if (i%2==1) cout<<v[i/2]<<"\n";
    }
    return 0;
}
2024/8/28 22:59
加载中...