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;
}
创作不易,对你有帮助的话可以点赞关注哦!
。兰州治疗肿瘤最好的医院上饶不孕不育医院哪家好
悟空祛痘
-
早报:法拉第未来21年亏损5.17亿美元 MSI八强赛收官
【Android中国人商报】康普顿将来(FF)近日公布2021年第四季度及年度财务业绩。数据表明,FF公司2021年净亏损5.17亿美元,2020年同期净亏损为1.47亿美元。MSI(侠盗Uni
-
约吗?泸州-广西南宁博鳌航线正式开通!2.5小时即可直达!
愤怒的心 颤抖的手 为大家带来一个 好 歧 收!!! 1月19日18点02分 华南地区东盟至成都航点 正式
- 09-11中山王濛把武大靖踢出直播间,发生了啥?
- 09-11CF暴君终结者和钢铁侠有何联系?看看他们的背景故事就知道了
- 09-11疫情下,一家3口住113㎡里,待一年都不觉得无聊,静享平凡穷困
- 09-11亚奥理事会相关负责人:北京在很大程度上提出了一个未来模式
- 09-1136氪首发 | 可获千万级天使轮融资,「爱化身」想让品牌与用户实现“元宇宙自由”
- 09-11看了她家,才知道什么是现代简约风,污垢大气,骨子里透着高级
- 09-11普京来访内嵌“大劳”?法国总统座驾才22万?
- 09-114000元内买75寸4K电视?分享一些你不告诉他的坑
- 09-11专业人士解答:为什么2022年《自已之路》仍难以被超越
- 09-11绿城中国赎回5亿美元永续本金,2年半内需偿还185亿元永续本金