滴滴笔试

第一题
思路:如果全为负数,则找出最大的一个负数;否则线性遍历。。可是只过了90%。。全为负数的有一个case..求大神指导10%在哪里

#include "iostream"

#include "string"

#include "cstdio"

#include "vector"

#include "cstring"

using namespace std;

long long num[ 100000 ];

int main()

{

    int n;

    while (cin>>n)

    {

        memset(num, 0 , sizeof (num));

        bool allneg= true ;

        for ( int i= 0 ;i<n;++i)

        {

            cin>>num[i];

            if (num[i]>= 0 ) allneg= false ;

        }

        long long mx=num[ 0 ],sum= 0 ;

        

        if (allneg)

        {

            for ( int i= 0 ;i<n;++i)

            {

                if (num[i]>mx)

                    mx=num[i];

            }

        }

        else

        {

            for ( int i= 0 ;i<n;++i)

            {

                if (sum< 0 ) sum= 0 ;

                sum=sum+num[i];

                if (sum>mx) mx=sum;

                

            }

        }

        cout<<mx<<endl;

    }

    return 0 ;

}

第二题
思路:map记录容量为x的桌子有多少张。。。然后将顾客按照金额降序排序,然后遍历顾客的数组,如果该批顾客的人数当前有桌子能容下,则选择容量大于顾客人数的最小容量的桌子,然后将对应的table数量减1.。。
感觉思路OK的啊。。交上去说内存超限。。。。什么鬼。。。最后句cout<<res<<endl;改成cout<<20<<endl;交上去过了一个case。。谁能给解释下?

#include "iostream"

#include "string"

#include "cstdio"

#include "cstring"

#include "map"

#include "algorithm"

using namespace std;

struct customer

{

    int count;

    int money;

};

customer cus[ 50000 ];

int cmp(customer a,customer b)

{

    return a.money>b.money;

}

int main()

{

    int n,m;

    while (cin>>n>>m)

    {

        memset(cus, 0 , sizeof (cus));

        map< int , int > table;

        int mx= 0 ;

        for ( int i= 0 ;i<n;++i)

        {

            int a;

            cin>>a;

            if (mx<a) mx=a;

            table[a]++;

        }

        

        

        for ( int i= 0 ;i<m;++i)

            cin>>cus[i].count>>cus[i].money;

        

        

        long long int res= 0 ;

        sort(cus,cus+m,cmp);

        for ( int i= 0 ;i<m;++i)

        {

            for ( int k=cus[i].count;k<=mx;++k)

            {

                if (table[k]> 0 )

                {

                    res+=cus[i].money;

                    table[k]--;

                    break ;

                }

            }

        }

        

        cout<<res<<endl;

    }

    return 0 ;

}


全部评论
主要是不给错误信息反馈有不知道怎么改了
点赞 回复 分享
发布于 2016-09-06 23:23

相关推荐

不愿透露姓名的神秘牛友
07-11 12:31
以前小时候我最痛恨出轨、偷情的人,无论男女,为什么会出轨?现在我成了自己最讨厌的人,没想到分享的东西在牛客会被这么多人看,大家的评价都很中肯,我也认同,想过一一回复,但我还是收声了,我想我应该说说这件事,这件事一直压在我心里,是个很大的心结,上面说了人为什么出轨,我大概能明白了。我们大一下半年开始恋爱,开始恋爱,我给出了我铭记3年的承诺,我对她好一辈子,我永远不会背叛,我责任心太重,我觉得跟了我,我就要照顾她一辈子,我们在一起3年我都没有碰过她,她说往东我就往东,她说什么我做什么,她要我干什么,我就干什么!在学校很美好,中途也出过一些小插曲,比如男闺蜜、男闺蜜2号等等等。但我都强迫她改掉了,我...
牛客刘北:两个缺爱的人是没有办法好好在一起的,但世界上哪有什么是非对错?你后悔你们在一起了,但是刚刚在一起的美好也是真的呀,因为其他人的出现,你开始想要了最开始的自己,你的确对不起自己,21岁的你望高物远,你完全可以不谈恋爱,去过你想要的生活,你向往自由,在一起之后,你要想的不是一个人,而是两个人,你不是变心了,就像你说的,你受够了,你不想包容了,冷静几天是你最优的选择,爱人先爱己。
社会教会你的第一课
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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