2019-09-17 百度开发笔试题讨论(三题全AC)

//第一题 让min(n,m)的那个一直减就行 AC
int main()
{
   //freopen("in.txt","r",stdin);
    cin>>n>>m>>k;
    int mi = min(n,m);
    long long t=0;
    int minn = INT_MAX;
    for(int i=0; i<=mi; ++i)
    {
        t = (mi-i)*max(n,m);
        if(t<k)
        {
            minn = min(minn,i);
            break;
        }
    }
    cout<<minn<<endl;
    return 0;
}

//第二题,简单的排序一下,类似于会场安排问题处理即可 AC 
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf  = 0x3f3f3f3f;
const LL Linf  = 1ll<<61;
const double pi= acos(-1.0);
const int MOD  = 1e9+7;
const int maxn = 1e5 + 233;
int n,m,t,cnt;

struct node
{
    int a,b;
}st[maxn];
int cmp(node t1, node t2)
{
    return t1.b<t2.b;
}
int main()
{
    //freopen("in.txt","r",stdin);
    cin>>t;
    while(t--)
    {
        cin>>n;
        long long  sum=0;
        int maxx= INT_MIN;
        for(int i=0; i<n; ++i)
        {
            cin>>st[i].a>>st[i].b;
            sum += st[i].a;
            maxx = max(maxx,st[i].b);
        }
        if(sum>maxx)
        {
            puts("No");
            continue;
        }
        sort(st,st+n,cmp);
        long long ans=0;
        bool ok= true;
        for(int i=0; i<n; ++i)
        {
            ans += st[i].a;
            if(ans > st[i].b)
            {
                ok=false;
                break;
            }
        }
        if(ok)
            puts("Yes");
        else
            puts("No");
    }
    return 0;
}

//第三题 不太会做 猜题意 居然 AC了
if (n==4) puts("niumei");
else puts("niuniu")
第三题有没有大佬来讲解一下思路呀
#百度##笔试题目##题解#

注意!此信息未认证,请谨慎判断信息的真实性!

全部评论
点赞 5 评论
分享