| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:优先级队列优化的 为什么老是WA 大牛指教呵~~In Reply To:优先级队列优化的 为什么老是WA 大牛指教呵~~ Posted by:20071121181 at 2009-08-20 19:53:21 > #include<iostream>
> #include<queue>
> #include<cstring>
> using namespace std;
> int map[303][303];
> int d[303],vis[303];
> int p;
> struct cmp
> {
> bool operator() (const int &a,const int &b)
> {
> return d[a]>d[b];
> }
> };
> priority_queue<int,vector<int>,cmp> cc;
> void primt(int s)
> {
> int i,x,y,sum=0;
> while(!cc.empty())
> cc.pop();
> for(i=0;i<=p;i++)
> d[i]=200000000;
> memset(vis,0,sizeof(vis));
> d[s]=0,vis[s]=1;
> cc.push(s);
> while(!cc.empty())
> {
> x=cc.top();
> cc.pop();
> if(d[x]!=200000000)
> {
> sum=sum+d[x];
> }
> //vis[x]=0;
> //cout<<x<<endl;
> for(i=1;i<=p;i++)
> {
> if(d[i]>map[x][i])
> {
> d[i]=map[x][i];
> if(vis[i]==0)
> {
> cc.push(i);
> vis[i]=1;
> }
> }
> }
> }
> cout<<sum<<endl;
> }
> int main()
> {
> int i,j,z;
> //freopen("in","r",stdin);
> while(cin>>p)
> {
> memset(map,0,sizeof(map));
> for(i=1;i<=p;i++)
> {
> for(j=1;j<=p;j++)
> {
> cin>>z;
> map[i][j]=z;
> }
> }
> primt(1);
> }
> }
因为是多个case
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator