From d34e7717dc26f5403e21e26d68e0fdbebeaa965c Mon Sep 17 00:00:00 2001 From: ljcjames Date: Mon, 15 Aug 2022 16:53:11 +0800 Subject: [PATCH] 8.15 --- 8.15/B-House Man/Readme.md | 12 ++++ 8.15/B-House Man/doc/Readme.md | 1 + 8.15/B-House Man/main.cpp | 101 +++++++++++++++++++++++++++++++++ 8.15/B-House Man/test/in.txt | 0 8.15/B-House Man/test/in3.txt | 3 + 8.15/B-House Man/test/out.txt | 7 +++ 8.15/F - Candies.cpp | 70 +++++++++++++++++++++++ 7 files changed, 194 insertions(+) create mode 100644 8.15/B-House Man/Readme.md create mode 100644 8.15/B-House Man/doc/Readme.md create mode 100644 8.15/B-House Man/main.cpp create mode 100644 8.15/B-House Man/test/in.txt create mode 100644 8.15/B-House Man/test/in3.txt create mode 100644 8.15/B-House Man/test/out.txt create mode 100644 8.15/F - Candies.cpp diff --git a/8.15/B-House Man/Readme.md b/8.15/B-House Man/Readme.md new file mode 100644 index 0000000..de262f7 --- /dev/null +++ b/8.15/B-House Man/Readme.md @@ -0,0 +1,12 @@ +# 题目 +* 链接 +### 题意 + +### 做法 + +### 关键词 + +### 易错点 + +### 工具箱 +* \ No newline at end of file diff --git a/8.15/B-House Man/doc/Readme.md b/8.15/B-House Man/doc/Readme.md new file mode 100644 index 0000000..4e768b5 --- /dev/null +++ b/8.15/B-House Man/doc/Readme.md @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/8.15/B-House Man/main.cpp b/8.15/B-House Man/main.cpp new file mode 100644 index 0000000..f256f84 --- /dev/null +++ b/8.15/B-House Man/main.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include +using namespace std; +const int N=1e3+5,N3=N*3,inf=0x3f3f3f3f; +int to[N3],ne[N3],w[N3],h[N],cnt=0,s=N-4,e,dist[N],been[N]; +bool in[N],wa=0; +int t,n,d; +struct Point +{ + int h,id; +}a[N]; +void add(int u,int v,int w1) +{ + to[++cnt]=v; + ne[cnt]=h[u]; + w[cnt]=w1; + h[u]=cnt; +} +void spfa() +{ + queueq;//queue没有自带函数清零 + q.push(s); + while(!q.empty()) + { + int u=q.front(); + q.pop(); + in[u]=0;//spfa的精髓!! + for(int i=h[u];i;i=ne[i]) + { + int v=to[i],w1=w[i]; +// printf("%d %d %d\n",u,v,w1); + if(dist[u]+w1=n) + { + wa=1; + return; + } +// printf("%d(%d) %d(%d) %d\n",u,dist[u],v,dist[v],w1); + if(!in[v]) + { + q.push(v); + in[v]=1; + } + } + } + } +} +bool cmp(Point a, Point b) +{ + return a.hv) swap(u,v); + add(u,v,d); +// add(v,u,-1); + } + s=a[1].ida[n].id? a[1].id:a[n].id; + dist[s]=0; + wa=0;//WA? 忘了 + spfa(); +// if(dist[e]>=inf) dist[e]=-1; + if(wa) printf("Case %d: %d\n",t1,-1); + else printf("Case %d: %d\n",t1,dist[e]); + } + return 0; +} diff --git a/8.15/B-House Man/test/in.txt b/8.15/B-House Man/test/in.txt new file mode 100644 index 0000000..e69de29 diff --git a/8.15/B-House Man/test/in3.txt b/8.15/B-House Man/test/in3.txt new file mode 100644 index 0000000..89083b0 --- /dev/null +++ b/8.15/B-House Man/test/in3.txt @@ -0,0 +1,3 @@ +1 +5 9 +1 2 5 3 4 \ No newline at end of file diff --git a/8.15/B-House Man/test/out.txt b/8.15/B-House Man/test/out.txt new file mode 100644 index 0000000..01ba092 --- /dev/null +++ b/8.15/B-House Man/test/out.txt @@ -0,0 +1,7 @@ +## z:\Chao\src\Template\test\in.txt +2020/03/14 周六 11:41:28.68 +Hello Easy C++ project! + +----------------------------------------------- +Process exited after 200 ms with return value 0 + diff --git a/8.15/F - Candies.cpp b/8.15/F - Candies.cpp new file mode 100644 index 0000000..a58a8e3 --- /dev/null +++ b/8.15/F - Candies.cpp @@ -0,0 +1,70 @@ +//youwu +#include +#include +#include +#include +#include +using namespace std; +const int N=3e4+5,N3=15e4+5,inf=0x3f3f3f3f; +int to[N3],ne[N3],w[N3],h[N],cnt=0,s=N-4,e,dist[N]; +bool in[N],wa=0,u,v,w1; +int n,m,maxn=0; +void add(int u,int v,int w1) +{ + to[++cnt]=v; + ne[cnt]=h[u]; + w[cnt]=w1; + h[u]=cnt; +} +void spfa() +{ + stackq;//queue没有自带函数清零 + q.push(s); + while(!q.empty()) + { + int u=q.top(); + q.pop(); + in[u]=0;//spfa的精髓!! + for(int i=h[u];i;i=ne[i]) + { + int v=to[i],w1=w[i]; +// printf("%d %d %d\n",u,v,w1); + if(dist[u]+w1maxn) +// { +// maxn=dist[i]; +// } +// } + printf("%d",dist[n]); + return 0; +}