本文整理汇总了C++中PQ::emplace方法的典型用法代码示例。如果您正苦于以下问题:C++ PQ::emplace方法的具体用法?C++ PQ::emplace怎么用?C++ PQ::emplace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PQ
的用法示例。
在下文中一共展示了PQ::emplace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
int n, m, l;
while (scanf("%d%d%d", &n, &m, &l) == 3) {
std::vector<std::vector<int>> graph(n);
for (int i = 0, a, b; i < m; ++ i) {
scanf("%d%d", &a, &b);
a --, b --;
graph[a].push_back(b);
graph[b].push_back(a);
}
if (l == 1) {
puts("1");
continue;
}
l --;
std::vector<std::vector<Info>> dp(1 << l, std::vector<Info>(n, Info { m + 1, 0 })),
merged(n, std::vector<Info>(1 << l, Info { m + 1, 0 }));
int root = l;
for (int i = 0; i < l; ++ i) {
dp[1 << i][i] = { 0, 1 };
}
for (int msk = 0; msk < 1 << l; ++ msk) {
for (int u = 0; u < n; ++ u) {
auto& ref = merged.at(u);
for (int subset = msk; subset > 0; subset = subset - 1 & msk) {
if (lowbit(subset) == lowbit(msk)) {
update(ref.at(msk), add(dp.at(subset).at(u), ref.at(msk ^ subset)));
}
}
}
for (int u = 0; u < n; ++ u) {
for (int v : graph[u]) {
update(dp.at(msk).at(v), add(merged.at(u).at(msk), ONE));
}
}
auto& ref = dp.at(msk);
PQ<std::pair<int, int>> pq;
for (int u = 0; u < n; ++ u) {
pq.emplace(ref.at(u).first, u);
}
while (!pq.empty()) {
auto top = pq.top();
pq.pop();
int u = top.second;
if (top.first == ref.at(u).first) {
for (int v : graph.at(u)) {
Info todo = add(ref.at(u), ONE);
if (todo.first < ref.at(v).first) {
pq.emplace(todo.first, v);
}
update(ref.at(v), todo);
}
}
}
for (int u = 0; u < n; ++ u) {
update(merged.at(u).at(msk), dp.at(msk).at(u));
// fprintf(stderr, "%s %d %d %d\n", std::bitset<3>(msk).to_string().c_str(), u, dp.at(msk).at(u).first, dp.at(msk).at(u).second);
}
}
printf("%d\n", merged.at(root).at((1 << l) - 1).second);
}
}
示例2: main
int main(){
CPPinput;
int H,n; cin>>H>>n;
// for(int i=1;i<=n;++i)cin>>t[i].first>>t[i].second;
for(int i=1;i<=n;++i)cin>>t[i].first>>h[i],t[i].second=1e9;
PQ<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> keytime;
for(int i=1;i<=n;++i)keytime.emplace(t[i].first,i),keytime.emplace(t[i].second,i);
if([&]()->bool{for(int i=1;i<=n;++i)if(h[i]==0)return 0;return 1;}())exit((cout<<-1<<endl,0));
double nowh=H,nowt=0;
int nowhole=0;
multiset<int> activeh;
while(nowh>eps){
PDE(nowh,nowt);
if(keytime.empty())exit((cout<<-1<<endl,0));
if(nowhole==0){
nowt=keytime.top().first;
int i=keytime.top().second;
keytime.pop();
if(int(nowt)==t[i].second)continue;
if(nowh<=h[i])continue;
nowhole++;
activeh.insert(h[i]);
continue;
}
double nkt=keytime.top().first;
int i=keytime.top().second;
// keytime.pop();
double dt=nkt-nowt;
double dh=dt*nowhole;
int nhh=*prev(activeh.end());
if(nhh!=0){
if(nowh-dh>=nhh){
keytime.pop();
nowt+=dt;
nowh-=dh;
if(int(nkt)==t[i].first){
if(nowh<=h[i]);
else{
nowhole++;
activeh.insert(h[i]);
}
}
else{
if(nowh<=h[i]);
else{
nowhole--;
activeh.erase(activeh.find(h[i]));
}
}
}
else{
dh=nowh-nhh;
dt=dh/nowhole;
nowt+=dt;
nowh-=dh;
activeh.erase(prev(activeh.end()));
nowhole--;
}
}
else{
keytime.pop();
if(dh>nowh)exit((cout<<fixed<<setprecision(14)<<nowt+nowh/nowhole<<endl,0));
else{
nowt+=dt;
nowh-=dh;
if(int(nkt)==t[i].first){
if(nowh<=h[i]);
else{
nowhole++;
activeh.insert(h[i]);
}
}
else{
if(nowh<=h[i]);
else{
nowhole--;
activeh.erase(activeh.find(h[i]));
}
}
}
}
}
cout<<fixed<<setprecision(14)<<nowt<<endl;
}