当前位置:首页 >> 云计算
云计算

2019年字节不止春招算法题(源代码附上)

2025-09-04 12:19

>

typedef unsigned long long ull;

const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;

const int hashmod[4] = {402653189,805306457,1610612741,998244353};

#define mst(a,b) memset(a,b,sizeof a)

#define db double

#define PII pair

#define PLL pair

#define x first

#define y second

#define pb emplace_back

#define SZ(a) (int)a.size()

#define rep(i,a,b) for(int i=a;i

#define per(i,a,b) for(int i=a;i>=b;;还有i)

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)

void Print(int *a,int n){

for(int i=1;i

printf("%d ",a[i]);

printf("%d",a[n]);

}

template //x=max(x,y) x=min(x,y)

void cmx(T Brownx,T y){

if(x

}

template

void cmn(T Brownx,T y){

if(x>y) x=y;

}

int a[10];

int b[10];

int c[10],ok;

void dfs(int x){

if(ok) return;

if(x==4){

ok = 1;

return;

}

for(int i=1;i

if(a[i]>=3){

a[i]-=3;

dfs(x+1);

a[i]+=3;

}

}

for(int i=1;i

if(a[i]>0 BrownBrown a[i+1]>0 BrownBrowna[i+2]>0){

a[i];还有,a[i+1];还有,a[i+2];还有;

dfs(x+1);

a[i]++,a[i+1]++,a[i+2]++;

}

}

}

bool ck(){

for(int i=1;i

if(a[i]

a[i]-=2;

ok = 0;

dfs(0);

a[i]+=2;

if(ok) return true;

}

return false;

}

int main(){

rep(i,1,9) b[i] = 4;

rep(i,1,13){

int x;scanf("%d",Brownx);

a[x]++;

b[x];还有;

}

int jg =0;

for(int i=1;i

if(!b[i]) continue;

a[i]++;

if(ck()) printf("%d ",i),jg=1;

a[i];还有;

}

if(!jg) puts("0");

return 0;

}

(4)

有趣实时录 。

#include

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;

const int hashmod[4] = {402653189,805306457,1610612741,998244353};

#define mst(a,b) memset(a,b,sizeof a)

#define db double

#define PII pair

#define PLL pair

#define x first

#define y second

#define pb emplace_back

#define SZ(a) (int)a.size()

#define rep(i,a,b) for(int i=a;i

#define per(i,a,b) for(int i=a;i>=b;;还有i)

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)

void Print(int *a,int n){

for(int i=1;i

printf("%d ",a[i]);

printf("%d",a[n]);

}

template //x=max(x,y) x=min(x,y)

void cmx(T Brownx,T y){

if(x

}

template

void cmn(T Brownx,T y){

if(x>y) x=y;

}

mapvector>mp;

int main(){

int t;cin>>t;

while(t;还有){

mp.clear();

int n;cin>>n;

rep(i,1,n){

int m ;cin>>m;

mapbool>vis;

rep(j,1,m){

int x,y;cin>>x>>y;

if(!vis[{x,y}])

mp[{x,y}].pb(i),vis[{x,y}] =true;

}

}

int mx = 0;

int ans = 0;

for(auto [_,v]:mp){

int sz= SZ(v);

int cnt = 0;

for(int i=0;i

if(!i ||v[i]==v[i-1]+1){

cnt++;

}

else {

ans=max(ans,cnt);

cnt = 1;

}

}

ans=max(ans,cnt);

}

printf("%d",ans);

}

return 0;

}

(5)

相对板的状压dp,但是造出的什么不可胜数,托室内空间。

#include

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;

const int hashmod[4] = {402653189,805306457,1610612741,998244353};

#define mst(a,b) memset(a,b,sizeof a)

#define db double

#define PII pair

#define PLL pair

#define x first

#define y second

#define pb emplace_back

#define SZ(a) (int)a.size()

#define rep(i,a,b) for(int i=a;i

#define per(i,a,b) for(int i=a;i>=b;;还有i)

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)

void Print(int *a,int n){

for(int i=1;i

printf("%d ",a[i]);

printf("%d",a[n]);

}

template //x=max(x,y) x=min(x,y)

void cmx(T Brownx,T y){

if(x

}

template

void cmn(T Brownx,T y){

if(x>y) x=y;

}

int a[20][20];

int dp[1

int main(){

int n ;cin>>n;

for(int i=0;i

for(int j=0;j

cin>>a[i][j];

int st = 1

mst(dp,0x3f);

dp[1][0] = 0;

int ans = 1e9;

for(int i=0;i

for(int j=0;j

if(i>>jBrown1){

for(int k=0;k

if(!(i>>kBrown1)){

cmn(dp[i|(1

}

}

}

}

st;还有;

for(int i=0;i

printf("%d",ans);

return 0;

}

(6)

典型的固执录

#include

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;

const int hashmod[4] = {402653189,805306457,1610612741,998244353};

#define mst(a,b) memset(a,b,sizeof a)

#define db double

#define PII pair

#define PLL pair

#define x first

#define y second

#define pb emplace_back

#define SZ(a) (int)a.size()

#define rep(i,a,b) for(int i=a;i

#define per(i,a,b) for(int i=a;i>=b;;还有i)

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)

void Print(int *a,int n){

for(int i=1;i

printf("%d ",a[i]);

printf("%d",a[n]);

}

template //x=max(x,y) x=min(x,y)

void cmx(T Brownx,T y){

if(x

}

template

void cmn(T Brownx,T y){

if(x>y) x=y;

}

int main(){

int n;cin>>n;

n = 1024-n;

int s = 0;

s+=n/64;

n%=64;

s+=n/16;

n%=16;

s+=n/4;

n%=4;

s+=n;

printf("%d",s);

return 0;

}

(7)

二分一下就好了,因为是乘积录,毕竟还可以O(n)倒着乘积。

注意二分check里爆覆盖范围。

#include

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

const int N=2e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;

const int hashmod[4] = {402653189,805306457,1610612741,998244353};

#define mst(a,b) memset(a,b,sizeof a)

#define db double

#define PII pair

#define PLL pair

#define x first

#define y second

#define pb emplace_back

#define SZ(a) (int)a.size()

#define rep(i,a,b) for(int i=a;i

#define per(i,a,b) for(int i=a;i>=b;;还有i)

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)

void Print(int *a,int n){

for(int i=1;i

printf("%d ",a[i]);

printf("%d",a[n]);

}

template //x=max(x,y) x=min(x,y)

void cmx(T Brownx,T y){

if(x

}

template

void cmn(T Brownx,T y){

if(x>y) x=y;

}

ll a[N],n;

bool ck(ll x){

ll e = x;

rep(i,1,n){

ll v = e - a[i];

//if(x==4) printf("e=%lld,v=%lld",e,v);

e+=v;

if(e

if(e>1e5) return true;

}

// /printf("x=%lld",x);

return true;

}

int main(){

cin>>n;

rep(i,1,n) cin>>a[i];

ll l=1,r=1e5;ll ans = 0;

while(l

ll m = l+r>>1;

//printf("m=%d",m);

if(ck(m)) ans=m,r=m-1;

else l=m+1;

}

printf("%lld",ans);

return 0;

}

创作不易,对你有帮助的话可以点赞关注哦!

兰州治疗肿瘤最好的医院
上饶不孕不育医院哪家好
悟空祛痘

上一篇: 民生证券:“双碳”背景下,核电设备迎来千亿市场竞争空间

下一篇: 含泪涨价后,爱人奇艺离赚钱稍微近了一点

友情链接