0
已解决
包涵宇
中级天翼
中级天翼
这题就是:
6180 密度最短路径
求助各位大佬!!!
我的WA0分代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<vector>
#include<limits>
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)
using namespace std;
struct node{
int x,q;
};
int n,m,w;
double da[55][55],mn,dis[55][1005];
vector <node>b[55];
bool f;
int can[55][55];
void dfs(int as,int xx,int s,int bian){
if(bian!=0&&s*1.0/bian>=dis[xx][bian])return ;
if(bian!=0)dis[xx][bian]=s*1.0/bian;
if(xx==as){
f=1;
mn=min(mn,s*1.0/bian);
return ;
}
for(int i=0;i<b[xx].size();i++){
dfs(as,b[xx][i].x,s+b[xx][i].q,bian+1);
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
int x,y,z;
cin>>x>>y>>z;
int ff=1;
for(int i=0;i<b[x].size();i++){
if(b[x][i].x==y){
if(b[x][i].q>y){
b[x][i].q=y;
}
ff=0;
}
}
if(ff)b[x].push_back(node{y,z});
}
cin>>w;
for(int i=1;i<=w;i++){
int a,b;
cin>>a>>b;
if(can[a][b]!=0){
if(can[a][b]==1)cout<<"OMG!\n";
else printf("%.3lf\n",int(da[a][b]*1000+0.5)/1000.0);
}
else{
f=0;
memset(dis,0x7fffffff,sizeof(dis));
mn=100000000;
dfs(b,a,0,0);
if(f==0){
can[a][b]=1;
cout<<"OMG!\n";
}
else{
da[a][b]=mn;
can[a][b]=2;
printf("%.3lf\n",int(mn*1000+0.5)/1000.0);
}
}
}
return 0;
}
可能有些长,各位稍安勿躁,读完!
(我相信大家都会复制代码)
再次声明:70个豆是我的全部家产!我很穷!!!
@董子墨@黄子澄!!!
包涵宇在2021-03-07 20:25:52追加了内容
AC了,谁回答送谁豆!
0
0
0
0
0
0
0