3月23阿里笔试 2题ac附代码

1、直接快速幂
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>
#include <string>
#include <complex>
using namespace std;

typedef long long ll;
ll power(ll a, ll n, ll mod)
{ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
//head

int main(){
    ll n;
    while(cin>>n)
    {
        cout<<n*power(2,n-1, mod)%mod<<endl;
        
    }

    return 0;
}



2、bfs搜一下
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>
#include <string>
#include <complex>
using namespace std;

typedef pair<int, int> pii;
const int maxn = 1e5+10, mod = 1e9 + 7;

queue<pair<int,pair<int,int> > > qu;
string s;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int a[600][600];
int flag[6][600][600];
int n,m;
bool judge(int x, int y, int kn)
{
    if(x<=n && x>=1 && y<=m && y>=1 && a[x][y] == 0 && flag[kn][x][y] == 0)
        return true;
    return false;
}
int main(){
    //freopen("C-small-attempt0.in","r",stdin);
    //freopen("C-small-attempt0.out","w",stdout);

    while(cin>>n>>m)
    {
        int sn,sm,en,em;
        while(!qu.empty())qu.pop();
        memset(flag,0, sizeof(flag));
        pair<int,pair<int,int> > dp, cur;
        for(int i=1;i<=n;i++)
        {
            cin>>s;
            for(int j=0;j<m;j++)
            {
                if(s[j] == 'S')
                    sn = i, sm = j +1 , a[i][j+1] = 0;
                if(s[j] == 'E')
                    en = i, em = j+1, a[i][j+1] = 0;
                if(s[j] == '.')
                    a[i][j+1] = 0;
                if(s[j] == '#')
                    a[i][j+1] = 1;
            }
        }

        dp.first = 0;
        dp.second.first = sn;
        dp.second.second = sm;
        qu.push(dp);
        flag[0][sn][sm] = 1;
        int ans = -1;
        while(!qu.empty())
        {
            dp = qu.front();
            int cx  = dp.second.first;
            int cy = dp.second.second;
            int knum = dp.first;
            int bus = flag[knum][cx][cy];
            qu.pop();
            //cout<<cx<<" "<<cy<<" "<<knum<<" "<<bus<<endl;
            if(cx == en && cy == em)
            {
                ans = bus - 1;
                break;
            }
            for(int i=0;i<4;i++)
            {
                if(judge(cx + dx[i], cy + dy[i], knum))
                {
                    cur.first = knum;
                    cur.second.first = cx + dx[i];
                    cur.second.second = cy + dy[i];
                    qu.push(cur);
                    flag[knum][cx + dx[i]][cy + dy[i]] = bus + 1;
                }

            }
            if(knum < 5 && judge(n + 1 - cx , m + 1 - cy , knum + 1))
            {
                cur.first = knum + 1;
                cur.second.first = n + 1 - cx;
                cur.second.second = m + 1 - cy;
                qu.push(cur);
                flag[knum + 1][n + 1 - cx][m + 1 - cy] = bus + 1;
            }
        }
        cout<<ans<<endl;



    }

    return 0;
}

#阿里笔试2020##笔试题目##阿里巴巴#
全部评论
第二题的飞行坐标是不是有点问题? 我觉得应该是flyX=n-1-x, flyY=m-1-y,笔试的时候我按照flyX=n+1-x, flyY=m+1-y来做,死活调不出来,笔试完后我改成上面那种,就能算出来了.....
2 回复 分享
发布于 2020-03-23 20:53
你这头文件写完都要10分钟吧
点赞 回复 分享
发布于 2020-03-26 22:48
需要用这么多头文件???
点赞 回复 分享
发布于 2020-03-24 16:24
第一题真的秀到了😂
点赞 回复 分享
发布于 2020-03-23 20:47

相关推荐

最近群里有很多同学找我看简历,问问题,主要就是集中在明年三月份的暑期,我暑期还能进大厂嘛?我接下来该怎么做?对于我来说,我对于双非找实习的一个暴论就是title永远大于业务,你在大厂随随便便做点慢SQL治理加个索引,可能就能影响几千人,在小厂你从零到一搭建的系统可能只有几十个人在使用,量级是不一样的。对双非来说,最难的就是约面,怎么才能被大厂约面试?首先这需要一点运气,另外你也需要好的实习带给你的背书。有很多双非的同学在一些外包小厂待了四五个月,这样的产出有什么用呢?工厂的可视化大屏业务很广泛?产出无疑是重要的,但是得当你的实习公司到了一定的档次之后,比如你想走后端,那么中厂后端和大厂测开的选择,你可以选择中厂后端(注意,这里的中厂也得是一些人都知道的,比如哈啰,得物,b站之类,不是说人数超过500就叫中厂),只有这个时候你再去好好关注你的产出,要不就无脑大厂就完了。很多双非同学的误区就在这里,找到一份实习之后,就认为自己达到了阶段性的任务,根本不再投递简历,也不再提升自己,玩了几个月之后,美其名曰沉淀产出,真正的好产出能有多少呢?而实际上双非同学的第一份实习大部分都是工厂外包和政府外包!根本无产出可写😡😡😡!到了最后才发现晚了,所以对双非同学来说,不要放过任何一个从小到中,从中到大的机会,你得先有好的平台与title之后再考虑你的产出!因为那样你才将将能过了HR初筛!我认识一个双非同学,从浪潮到海康,每一段都呆不久,因为他在不断的投递和提升自己,最后去了美团,这才是双非应该做的,而我相信大部分的双非同学,在找到浪潮的那一刻就再也不会看八股,写算法,也不会打开ssob了,这才是你跟别人的差距。
迷茫的大四🐶:我也这样认为,title永远第一,只有名气大,才有人愿意了解你的简历
双非本科求职如何逆袭
点赞 评论 收藏
分享
评论
点赞
14
分享

创作者周榜

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