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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

牛客月赛42题解【完结】

發(fā)布時間:2025/3/20 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 牛客月赛42题解【完结】 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

目錄

  • 冰獄寒嵐【簡單】
  • 光之屏障【簡單】
  • 寒潭煙光【簡單】
  • 金蛇狂舞【bfs】
  • 暗滅侵蝕【模擬】
  • 火鳳燎原【思維】

冰獄寒嵐【簡單】


https://ac.nowcoder.com/acm/contest/26561/A
就是打表即可,然后查詢即可。

#include<bits/stdc++.h> using namespace std; int n,m,t; vector<int>ve; int main(void) {for(int i=0;i<1024;i++) ve.push_back(i);for(int i=1024;i>0;i--) ve.push_back(-i);cin>>n;while(n--){int x; cin>>x;cout<<ve[x%2048]<<" ";}return 0; }

光之屏障【簡單】

https://ac.nowcoder.com/acm/contest/26561/B
打表,二分找答案。

#include<bits/stdc++.h> using namespace std; typedef long long int LL; vector<LL>ve; int main(void) {int t; cin>>t;for(int i=0;i<=31;i++) ve.push_back(pow(2,i));while(t--){LL a,b; cin>>a>>b;int l=lower_bound(ve.begin(),ve.end(),a)-ve.begin();int r=upper_bound(ve.begin(),ve.end(),b)-ve.begin();if(l>=r) puts("-1");else cout<<ve[l]<<endl;}return 0; }

想復雜了,數(shù)據(jù)很小,其實直接模擬即可。

#include<bits/stdc++.h> using namespace std; typedef long long int LL; vector<LL>ve; int main(void) {int t; cin>>t;while(t--){LL a,b; cin>>a>>b;LL sum=1;while(sum<a) sum*=2;if(sum>=a&&sum<=b) cout<<sum<<endl;else cout<<-1<<endl;}return 0; }

寒潭煙光【簡單】


https://ac.nowcoder.com/acm/contest/26561/C
他這個是,前綴和數(shù)組的平均值,加一個x,總和加了(n+1)*x

#include<bits/stdc++.h> using namespace std; typedef long long int LL; int main(void) {int t; cin>>t;while(t--){LL n,f,x0; cin>>n>>f>>x0;LL sum=(n*(f+x0)+x0)/(n+1);cout<<sum<<endl;}return 0; }

金蛇狂舞【bfs】


https://ac.nowcoder.com/acm/contest/26561/D
bfs即可,通過數(shù)據(jù)范圍可以知道階乘一般不會太大,因為太大顯然是無意義的。

#include<bits/stdc++.h> using namespace std; typedef long long int LL; const int N=15; LL f[N]; LL bfs(int x,int y) { unordered_map<LL,LL>mp; mp[x]=1;queue<pair<LL,LL>>q; q.push({x,0});while(q.size()){auto temp=q.front(); q.pop();int u=temp.first,step=temp.second;if(step>7) continue;if(u==y) return step;LL a[3]={0};a[1]=ceil(sqrt(u*1.0)),a[2]=floor(sqrt(u*1.0));if(u>15) a[0]=0;else a[0]=f[u];for(int i=0;i<3;i++){if(!i&&u>=N) continue;if(!mp[a[i]]) {q.push({a[i],step+1});mp[a[i]]++;}}}return -1; } int main(void) {f[0]=1;for(int i=1;i<N;i++) f[i]=f[i-1]*i;LL t; cin>>t;while(t--){LL x,y; cin>>x>>y;cout<<bfs(x,y)<<endl;}return 0; }

暗滅侵蝕【模擬】


https://ac.nowcoder.com/acm/contest/26561/E

#include<bits/stdc++.h> using namespace std; typedef long long int LL; int main(void) {LL t; cin>>t;while(t--){LL a[3],n;priority_queue<LL>heap;for(int i=0;i<3;i++) cin>>a[i],heap.push(a[i]);cin>>n;int cnt=0;while(1){for(int i=0;i<3;i++) a[i]=heap.top(),heap.pop();if(a[0]>=n) break;a[2]=a[0]*2-a[2];for(int i=0;i<3;i++) heap.push(a[i]);cnt++;}cout<<cnt<<endl;}return 0; }

火鳳燎原【思維】


https://ac.nowcoder.com/acm/contest/26561/F
就是,統(tǒng)計每個點的度,然后枚舉每一個點計算其貢獻。
根據(jù)題意可知,只有度大于等于3才是蒲公英。

#include<bits/stdc++.h> using namespace std; typedef long long int LL; const int N=1e5+10; int d[N],t,n; int main(void) {cin>>t;while(t--){cin>>n;for(int i=0;i<=n;i++) d[i]=0;for(int i=1;i<n;i++) {int a,b; scanf("%d%d",&a,&b);d[a]++,d[b]++;}LL ans=0;for(int i=1;i<=n;i++)//枚舉每一個點if(d[i]>=3) ans+=n-1-d[i];printf("%lld\n",ans);}return 0; }

總結(jié)

以上是生活随笔為你收集整理的牛客月赛42题解【完结】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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