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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Acwing第 29 场周赛【完结】

發布時間:2025/3/20 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Acwing第 29 场周赛【完结】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

TLE場

目錄

  • 4194. Pow【簽到】
  • 4195. 線段覆蓋【離散化+差分】
  • 4196. 最短路徑【最短路】

4194. Pow【簽到】


https://www.acwing.com/problem/content/description/4197/

#include<bits/stdc++.h> using namespace std; int main(void) {int t,n; cin>>n>>t;double ans=n;for(int i=1;i<=t;i++) ans*=1.00011;printf("%.6lf",ans);return 0; }

4195. 線段覆蓋【離散化+差分】


https://www.acwing.com/problem/content/description/4198/

  • 注意開long long
  • 用map來離散化的差分
  • 最后枚舉每一段
#include<bits/stdc++.h> using namespace std; typedef long long int LL; unordered_map<LL,LL>mp; const int N=1e5*2+10; LL cnt[N],n,l,r; vector<LL>ve; void insert(LL l,LL r,LL c) {mp[l]+=1;mp[r+1]-=1; } int main(void) {scanf("%lld",&n);for(int i=0;i<n;i++){scanf("%lld%lld",&l,&r);insert(l,r,1);ve.push_back(l);ve.push_back(r+1);}sort(ve.begin(),ve.end());ve.erase(unique(ve.begin(),ve.end()),ve.end());int sum=0;for(int i=0;i<ve.size();i++){if(i) cnt[sum]+=ve[i]-ve[i-1];//這一段的長度sum+=mp[ve[i]];}for(int i=1;i<=n;i++) cout<<cnt[i]<<" ";return 0; }

4196. 最短路徑【最短路】


最短路板子題,注意開long long。
注意這里都是正邊,故不存在負環。

#include<bits/stdc++.h> using namespace std; const int N=1e5*3+10; typedef long long int LL; typedef pair<LL,LL> PII; LL h[N],e[N],ne[N],w[N],idx; LL n,m,dist[N],st[N]; void add(LL a,LL b,LL c) {e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++; } vector<LL>path,ans; void Dijkstra(LL node) {memset(dist,0x3f,sizeof dist);memset(st,0,sizeof st);dist[node]=0;priority_queue<PII,vector<PII>,greater<PII>> heap; heap.push({0,node});while(heap.size()){auto t=heap.top(); heap.pop();int u=t.second;if(st[u]) continue;st[u]=1;for(int i=h[u];i!=-1;i=ne[i]){int j=e[i];if(dist[j]>dist[u]+w[i]){dist[j]=dist[u]+w[i];heap.push({dist[j],j});}}} } void dfs(int u) {if(ans.size()) return;if(u==n) {ans=path;ans.push_back(u);}for(int i=h[u];i!=-1;i=ne[i]){int j=e[i];if(ans.size()) return;if(st[j]) continue;else if(dist[j]==dist[u]+w[i]){path.push_back(u);st[u]=1;dfs(j);path.pop_back();}} } void init() {idx=0;memset(h,-1,sizeof h); } int main(void) {init();std::ios::sync_with_stdio(false);std::cin.tie(0);cin>>n>>m;for(int j=0;j<m;j++){LL a,b,c; cin>>a>>b>>c;add(a,b,c),add(b,a,c);}Dijkstra(1);if(dist[n]>1e12) cout<<-1;else {memset(st,0,sizeof st);dfs(1);for(int i=0;i<ans.size();i++) cout<<ans[i]<<" ";}return 0; }

總結

以上是生活随笔為你收集整理的Acwing第 29 场周赛【完结】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。