借个光,谁能告诉我着为什么错了

P1001 A+B Problem

WaltVBAlston @ 2020-02-26 12:15:57

第一次用lower_bound,编译错误

我看网上的大佬都是这么写的

谁能告诉我为什么编译错误?

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int a[100001];
vector <int> v;
int n;
int x;
bool cmp(int o,int z)
{
    return o<z;
}
int main()
{
    cin>>n;
    v.push_back(0);
    for(int i=1;i<=n;i++)
    {
        int m;
        cin>>m;
        a[i]=m;
        v.push_back(m);
    }
    sort(a+1,a+n+1,cmp);
    sort(v.begin()+1,v.end(),cmp);
    cin>>x;
    for(int i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
    for(int i=1;i<=v.size()-1;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
    int p=lower_bound(a+1,a+n+1,x);
    cout<<p<<endl;
    p=lower_bound(v.begin()+1,v.end(),x);
    cout<<p<<endl;
    return 0;
}

by DeepSkyBlue__ @ 2020-02-26 12:16:43

@Andy_2006 ……


by 01190220csl @ 2020-02-26 12:16:46

@Andy_2006 CE是显然的 lower_bound返回的是指针/迭代器


by jijidawang @ 2020-02-26 12:17:41

@Andy_2006 要-a


by YUYGFGG @ 2020-02-26 12:19:09

STL太慢


by WaltVBAlston @ 2020-02-26 12:25:45

那vector怎么用呢


by FZzzz @ 2020-02-26 12:37:58

@Andy_2006 -a.begin()


by CarroT1212 @ 2020-02-26 12:53:43

你确定这个问题要这么复杂的解法吗……


by HyyypRtf06 @ 2020-02-26 12:57:43

@龚特_201912_Pg 看下题解区谢谢qvq


by CarroT1212 @ 2020-02-26 13:09:19

@ HyyypRtf06 不是不到10行就够了吗?


by easyf12 @ 2020-02-27 20:47:41

我劝你不要写太长,


| 下一页