暴力也可以,题目数据水。

选药

https://www.nowcoder.com/practice/f55f93b3560248f4b4532490206df398

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct good
{
    int a,b;
};
bool cmp(good A,good B)
{
    return A.b>B.b;
}
int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
int n;cin>>n;
vector<good> goods;
int o=n;
while(o--)
{
    int a,b;cin>>a>>b;
    goods.push_back({a,b});
}//0  n-1
sort(goods.begin(),goods.end(),cmp);//按效果排序
int q;cin>>q;
while(q--)
{
    int x;cin>>x;
    int flag=0;
    for(int i=0;i<n;i++)
    {  
        if(goods[i].a<=x)
        {
            cout<<goods[i].b<<endl;
            flag=1;
            break;
        }
       
    }
     if(flag==0)
       { cout<<-1<<endl;}
}
    return 0;
}

全部评论
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct good { int a,b; }; bool cmp(good A,good B) { return A.a<b.a>>n; vector<good> goods; for(int i=0;i<n>>a>>b; goods.push_back({a,b}); } sort(goods.begin(),goods.end(),cmp); int q;cin>>q; vector<int>MAX(n); MAX[0]=goods[0].b; for(int i=1;i<n>>x; int p=upper_bound(goods.begin(),goods.end(),good{x,0},cmp)-goods.begin(); if(p==0) { cout<<-1<</n></int></n></good></b.a></algorithm></vector></iostream>
1 回复 分享
发布于 11-26 13:05 河北

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务