唯一写出来的一题,但也华丽丽地跪了……比赛的时候没有看清可以同时多对一起跳舞,果断跪了
直接先最短路一下,然后除3,因为每3个人才能认识一个新人
#include <vector> #include <list> #include <cstring> #include <set> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; class DancingFoxes { public: int minimalDays(vector <string>); }; struct node { int v,now; friend bool operator <(node a,node b) { return a.now>b.now; } }; int dijkstra(int v,vector <string> M) { priority_queue<node> q; bool don[51]; int Dis[55]; int n=M.size(); memset(don,0,sizeof(don)); memset(Dis,63,sizeof(Dis)); Dis[v]=0; node now,next; now.v=v; now.now=0; q.push(now); while(!q.empty()) { now=q.top();q.pop(); int v=now.v; // cout<<now.v<<endl; if(don[v])continue; don[v]=1; for(int i=0;i<n;i++) { if(M[v][i]=='N')continue; int t=Dis[v]+1; if(t>=Dis[i])continue; Dis[i]=t; next.v=i; next.now=t; q.push(next); } } if(Dis[1]==Dis[54])return -1; int ans=0,t=Dis[1]+1; while(t>2) { t-=t/3; ans++; } return ans; } int DancingFoxes::minimalDays(vector <string> friendship) { return dijkstra(0,friendship); } //Powered by [KawigiEdit] 2.0!