日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > php >内容正文

php

今日头条PHP开发工程师面试,今日头条2018春招研发岗第一次笔试题解

發(fā)布時(shí)間:2025/3/12 php 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 今日头条PHP开发工程师面试,今日头条2018春招研发岗第一次笔试题解 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

第一題:

雙指針:

#include

using namespace std;

typedef long long ll;

const int N = 1e6+7;

int a[N];

int main()

{

int n,k;

scanf("%d%d",&n,&k);

for(int i=0;i

sort(a, a+n);

n = unique(a, a+n) -a;

int r = 0, ans=0;

for(int l=0; l

{

while(r

if(r==n) break;

if(a[r]-a[l] == k) ++ans;

}

printf("%d\n", ans);

return 0;

}

第二題:

BFS

#include

using namespace std;

typedef pair pii;

map , int > mp;

int main()

{

int n;

scanf("%d",&n);

queue q;

q.push(make_pair(1, 1));

mp[make_pair(1,1)]=0;

while(!q.empty())

{

pii pr = q.front();q.pop();

//? ? ? ? printf("%d %d\n",pr.first, pr.second);

if(pr.first == n)

{

printf("%d\n", mp[pr]);

exit(0);

}

pii t=pr;

t.second = t.first; t.first*=2;

if(!mp.count(t))

{

q.push(t);

mp[t] = mp[pr]+1;

}

t=pr;

t.first=t.first+t.second;

if(!mp.count(t))

{

q.push(t);

mp[t] = mp[pr]+1;

}

}

return 0;

}

第三題:

模擬。

#include

using namespace std;

typedef long long ll;

char s[107];

char G[5][10][8] = {

{"66666", "....6", "66666", "66666", "6...6", "66666", "66666", "66666", "66666", "66666"},

{"6...6", "....6", "....6", "....6", "6...6", "6....", "6....", "....6", "6...6", "6...6"},

{"6...6", "....6", "66666", "66666", "66666", "66666", "66666", "....6", "66666", "66666"},

{"6...6", "....6", "6....", "....6", "....6", "....6", "6...6", "....6", "6...6", "....6"},

{"66666", "....6", "66666", "66666", "....6", "66666", "66666", "....6", "66666", "66666"}

};

ll cal()

{

int n = strlen(s);

ll sum=0, cur=0, prd=1;

for(int i=0; i

{

if(isdigit(s[i])) cur=cur*10+s[i]-'0';

else if(s[i] == '-')

{

sum+=prd*cur;

cur=0;

prd=-1;

}

else if(s[i] == '+')

{

sum+=prd*cur;

cur=0;

prd=1;

}

else

{

prd*=cur;

cur=0;

}

}

return sum+prd*cur;

}

int main()

{

int T;

scanf("%d",&T);while(T--)

{

scanf("%s", s);

ll ans = cal();

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

{

vector v;

ll tmp = ans;

while(tmp) v.push_back(tmp%10),tmp/=10;

reverse(v.begin(), v.end());

if(v.empty()) v.push_back(0);

for(int j=0; j

{

printf("%s%s",G[i][v[j]], j+1==v.size()?"\n":"..");

}

}

}

return 0;

}

第四題:

只能從均值大的集合往均值小的集合里放。

取數(shù)只能取出現(xiàn)次數(shù)等于1的數(shù)

放數(shù)只能放沒出現(xiàn)過的數(shù)

從小的數(shù)開始放可以使均值小的集合均值上升慢,均值大的集合均值上升快,這樣最優(yōu)。

#include

using namespace std;

typedef long long ll;

set sa,sb;

ll suma, sumb;

const long double eps = 1e-14;

inline int cmp(long double a, long double b)

{

if(fabs(a-b) <= eps) return 0;

return a>b?1:-1;

}

inline long double jz(ll k, int m)

{

return (long double)k/m;

}

int main()

{

int n,m;

scanf("%d%d",&n,&m);

for(int i=0; i

{

int t;

scanf("%d",&t);

sa.insert(t);

suma+=t;

}

for(int i=0;i

{

int t;

scanf("%d",&t);

sb.insert(t);

sumb+=t;

}

if(cmp(jz(suma, n), jz(sumb, m))==-1)

{

swap(suma, sumb);

swap(n, m);

sa.swap(sb);

}

int mx =n;

int ans = 0;

for(auto k : sa)

{

if(cmp(k, jz(suma, n)) >= 0) break;

//? ? ? ? printf("%d %d\n",n, k);

if(!sb.count(k)&&cmp(k, jz(sumb, m))>0)

{

++ans;

sumb+=k;

suma-=k;

sb.insert(k);

--n;++m;

}

}

printf("%d\n", ans);

第五題:BFS

#include

using namespace std;

const int N = 1e5+1000;

typedef pair pii;

bool vis[N];

int a[N];

int main()

{

int n,k,h;

scanf("%d%d%d",&n,&k,&h);

for(int i=0;i

{

int t;

scanf("%d",&t);

a[t]=1;

}

queue q;

q.push({0,0});

int ans = 0;

while(!q.empty())

{

pii p = q.front(); q.pop();

if(p.second>k) break;

ans = max(ans, p.first);

for(int i=1; i<=h; ++i)

{

if(a[p.first + i]&&!vis[p.first+2*i])

{

vis[p.first+2*i]=true;

q.push(make_pair(p.first+2*i, p.second+1));

}

if(p.first-2*i>0&&a[p.first-i]&&!vis[p.first-2*i])

{

vis[p.first-2*i]=true;

q.push(make_pair(p.first-2*i, p.second+1));

}

}

}

printf("%d\n", ans);

return 0;

}

總結(jié)

以上是生活随笔為你收集整理的今日头条PHP开发工程师面试,今日头条2018春招研发岗第一次笔试题解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。