
目录TLE场
- 4194. Pow【签到】
- 4195. 线段覆盖【离散化+差分】
- 4196. 最短路径【最短路】
https://www.acwing.com/problem/content/description/4197/
#include4195. 线段覆盖【离散化+差分】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; }
https://www.acwing.com/problem/content/description/4198/
- 注意开long long
- 用map来离散化的差分
- 最后枚举每一段
#includeusing namespace std; typedef long long int LL; unordered_map mp; const int N=1e5*2+10; LL cnt[N],n,l,r; vector 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 4196. 最短路径【最短路】
最短路板子题,注意开long long。
注意这里都是正边,故不存在负环。#includeusing namespace std; const int N=1e5*3+10; typedef long long int LL; typedef pair 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 path,ans; void Dijkstra(LL node) { memset(dist,0x3f,sizeof dist); memset(st,0,sizeof st); dist[node]=0; priority_queue ,greater > 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 >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 欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)