生活随笔
收集整理的這篇文章主要介紹了
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。
注意這里都是正邊,故不存在負環(huán)。
#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 场周赛【完结】的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。