SDUT series, sdut Series

Source: Internet
Author: User

SDUT series, sdut Series
SDUT2929 _ a series of live pig series: Fang Jie and Fang Jie's pig
Find all the shortest paths in the solution report, and enumerate a pigsty to find the shortest path of a pigsty with pig.

#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define inf 99999999using namespace std;struct E{    int v,w,next;} edge[5000];int head[1000],cnt,n,m,k,dis[1000][1000],vis[1000];int _hash[1000];void spfa(int s){    queue<int>Q;    int i,j;    for(i=1; i<=m; i++)    {        dis[s][i]=inf;        vis[i]=0;    }    dis[s][s]=0;    vis[s]=1;    Q.push(s);    while(!Q.empty())    {        int u=Q.front();        Q.pop();        vis[u]=0;        for(i=head[u]; i!=-1; i=edge[i].next)        {            if(dis[s][edge[i].v]>dis[s][u]+edge[i].w)            {                dis[s][edge[i].v]=dis[s][u]+edge[i].w;                if(!vis[edge[i].v])                {                    vis[edge[i].v]=1;                    Q.push(edge[i].v);                }            }        }    }}void add(int u,int v,int w){    edge[cnt].v=v;    edge[cnt].w=w;    edge[cnt].next=head[u];    head[u]=cnt++;}int main(){    int i,j,t,u,v,w;    while(~scanf("%d%d%d",&n,&m,&k))    {        cnt=0;        memset(head,-1,sizeof(head));        memset(_hash,0,sizeof(_hash));        memset(edge,0,sizeof(edge));        for(i=1; i<=n; i++)        {            scanf("%d",&t);            _hash[t]++;        }        for(i=1; i<=k; i++)        {            scanf("%d%d%d",&u,&v,&w);            add(u,v,w);            add(v,u,w);        }        for(i=1; i<=m; i++)        {            spfa(i);        }        int minn=inf,sum;        for(i=1; i<=m; i++)        {            sum=0;            for(j=1; j<=m; j++)            {                if(_hash[j])                    sum+=dis[i][j]*_hash[j];            }            if(minn>sum)            {                minn=sum;            }        }        printf("%d\n",minn);    }    return 0;}

Sdut2930_people living series meeting issue report find all the shortest paths in 'Z' Island, and then find the island that first reaches the Main Island
#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define inf 99999999using namespace std;struct E{    int v,w,next;} edge[50000];int head[1000],dis[1000],vis[1000],cnt,m,_hash[1000];void add(int u,int v,int w){    edge[cnt].v=v;    edge[cnt].w=w;    edge[cnt].next=head[u];    head[u]=cnt++;}void spfa(int s){    int i,j;    for(i='A'; i<='z'; i++)    {        dis[i]=inf;        vis[i]=0;    }    vis[s]=1;    dis[s]=0;    queue<int>Q;    Q.push(s);    while(!Q.empty())    {        int u=Q.front();        Q.pop();        vis[u]=0;        for(i=head[u]; i!=-1; i=edge[i].next)        {            if(dis[edge[i].v]>dis[u]+edge[i].w)            {                dis[edge[i].v]=dis[u]+edge[i].w;                if(!vis[edge[i].v])                {                    vis[edge[i].v]=1;                    Q.push(edge[i].v);                }            }        }    }}int main(){    int i,j,w;    char a[10],b[10];    while(~scanf("%d",&m))    {        memset(head,-1,sizeof(head));        memset(_hash,0,sizeof(_hash));        memset(edge,0,sizeof(edge));        cnt=0;        for(i=1; i<=m; i++)        {            scanf("%s%s%d",a,b,&w);            int u=a[0];            int v=b[0];            _hash[u]=1;            _hash[v]=1;            add(u,v,w);            add(v,u,w);        }        spfa('Z');        int minn=inf,u;        for(i='A'; i<'Z'; i++)        {            if(_hash[i])            {                if(minn>dis[i])                {                    minn=dis[i];                    u=i;                }            }        }        printf("%c %d\n",u,minn);    }}

SDUT2931 _ people live series Cui Shen love Tanabata problem report attention is to take a piece of cake each time to cut, so the answer is K-1
Sdut2932_human Survival series your backpack solution report simple prime screening.
SDUT2933 _ Streetlights
Solution report bare minimum spanning tree
SDUT2937 _ the series of people living to find the most perfect life problem report can be greedy, can generate a tree with the minimum.
What is the value of human life?

There are several types of values in life.

1. Busy travelers
Passively go forward, work, rest, life, and death. The journey of life is just like watching flowers.
2. Unscrupulous means for personal interests
Personal interests, such as excessive greed for fame and fortune, do not even take responsibility for any means to harm others.
3. Strive for personal goals
Set personal goals, such as becoming a master of art, a professor, and a world champion. to achieve this goal, do not harm people as much as possible. if you do not harm your own interests, you are also very happy with the interests of others.
4. benefit others and realize self-value
Do our best to benefit the society and others, so as to realize the value of self in the process of bringing happiness to others.
5. Pursuing Truth and realizing everything
I am not satisfied with the above and sought the way to realize the truth. Why are you and me different from each other? Why is there suffering in the world...
The practice is not to let go of the world, 'small hiding in the wild, big hiding in the city, huge hiding in the DPRK '.
The old man said, "Do not do for", behavior is sent to nature, interests of others without knowing themselves. True detachment and relief.
* There are many 1st categories, and many ordinary people may be in a "confused" state, day after day.
* There are very few of the 2nd categories, and a few of them will be eager to go to the extreme.
* There are many of the 3rd categories. Many people are struggling for their own business, have basic moral standards, and contribute to society in their positions.
* There are very few of the 4th categories, and there are not many personal thoughts at this level.
* There are very few of the 5th categories. The true pursuit of truth is rare and belongs to the ranks of saints.
What is your category? What type do you want to be?
What is the value of life? All in your choice.

Why are people living?

By chance, I will give anonymous users a short article: I hope to inspire you:

<Live>

As long as we live for one day, we should dedicate ourselves;

Strive for the beauty and progress of all mankind, the world, and the universe.

Our vision must be far beyond the limits of life;

It must be elegant and at no cost;

Must be great, great to Fearless.

With this kind of knowledge, any obstacle is insignificant,

Any personal inconvenience will not be worth mentioning.

We need to constantly expand and contribute our love to the world,

Creates a planet of love and peace.
Reference: hi.baidu.com/chinghai/profile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.