您的位置:首页 > 文旅 > 美景 > 网站系统繁忙是什么原因_莆田制作网站企业_网络营销实训总结报告_下载一个百度导航

网站系统繁忙是什么原因_莆田制作网站企业_网络营销实训总结报告_下载一个百度导航

2025/1/8 2:43:57 来源:https://blog.csdn.net/2401_88085478/article/details/144947485  浏览:    关键词:网站系统繁忙是什么原因_莆田制作网站企业_网络营销实训总结报告_下载一个百度导航
网站系统繁忙是什么原因_莆田制作网站企业_网络营销实训总结报告_下载一个百度导航

Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle in the early years. When a boy A had a crush on a girl B, he would usually not contact her directly in the first place. Instead, he might ask another boy C, one of his close friends, to ask another girl D, who was a friend of both B and C, to send a message to B -- quite a long shot, isn't it? Girls would do analogously.

Here given a network of friendship relations, you are supposed to help a boy or a girl to list all their friends who can possibly help them making the first contact.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers N (1 < N ≤ 300) and M, being the total number of people and the number of friendship relations, respectively. Then M lines follow, each gives a pair of friends. Here a person is represented by a 4-digit ID. To tell their genders, we use a negative sign to represent girls.

After the relations, a positive integer K (≤ 100) is given, which is the number of queries. Then K lines of queries follow, each gives a pair of lovers, separated by a space. It is assumed that the first one is having a crush on the second one.

Output Specification:

For each query, first print in a line the number of different pairs of friends they can find to help them, then in each line print the IDs of a pair of friends.

If the lovers A and B are of opposite genders, you must first print the friend of A who is of the same gender of A, then the friend of B, who is of the same gender of B. If they are of the same gender, then both friends must be in the same gender as theirs. It is guaranteed that each person has only one gender.

The friends must be printed in non-decreasing order of the first IDs, and for the same first ones, in increasing order of the seconds ones.

Sample Input:

10 18
-2001 1001
-2002 -2001
1004 1001
-2004 -2001
-2003 1005
1005 -2001
1001 -2003
1002 1001
1002 -2004
-2004 1001
1003 -2002
-2003 1003
1004 -2002
-2001 -2003
1001 1003
1003 -2001
1002 -2001
-2002 -2003
5
1001 -2001
-2003 1001
1005 -2001
-2002 -2004
1111 -2003

Sample Output:

4
1002 2004
1003 2002
1003 2003
1004 2002
4
2001 1002
2001 1003
2002 1003
2002 1004
0
1
2003 2001
0

题目大意:A对B有好感,但是不能A直接联系B,而是要通过和A同性的朋友C,C去联系和B同性的D。即A->C->D->B。注意C不能直接联系B,D也不能直接联系A。每个人用4位数字代表自己的编号,且正数代表男性,负数代表女性。输出时不用考虑性别,先输出C的编号,再输出B的编号。顺序要求为按照C的编号从小到大排序,当C的编号相等时,按照D的编号从小到大排序。

分析:可以先找到所有A的同性朋友C,再找到所有B的同性朋友D,之后判断C能够联系到哪些D即可。注意到可能存在0000和-0000,所以读入时要按照字符串读入。

#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define INF 0xffffffff
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define db4(x,y,z,r) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<endl
#define db5(x,y,z,r,w) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<", "<<#w<<"="<<(w)<<endl
using namespace std;typedef struct node
{int a,b;
}node;bool cmp(node a,node b)
{if(a.a!=b.a)return a.a<b.a;return a.b<b.b;
}int tonum(char *s)
{int f=1,t=0,num=0;if(s[0]=='-')f=-1,t++;for(int i=t;s[i];++i){num=num*10+s[i]-'0';}return num*f;
}int main(void)
{#ifdef testfreopen("in.txt","r",stdin);//freopen("in.txt","w",stdout);clock_t start=clock();#endif //testint n,m;scanf("%d%d",&n,&m);int gender[10005]={0};vector<int>num[10005];for(int i=0;i<m;++i){int a,b;char s1[10],s2[10];scanf("%s%s",s1,s2);a=tonum(s1);b=tonum(s2);
//        db2(a,b);int ga=1,gb=1;if(s1[0]=='-')ga=-1;if(s2[0]=='-')gb=-1;a=a*ga,b=b*gb,gender[a]=ga,gender[b]=gb;
//        db4(a,b,gender[a],gender[b]);num[a].push_back(b);num[b].push_back(a);}int k;scanf("%d",&k);while(k--){int a,b;char s1[10],s2[10];scanf("%s%s",s1,s2);a=tonum(s1);b=tonum(s2);
//        db2(a,b);int ga=1,gb=1;if(s1[0]=='-')ga=-1;if(s2[0]=='-')gb=-1;a=a*ga,b=b*gb,gender[a]=ga,gender[b]=gb;//        db3(k,a,b);vector<int>temp1,temp2;int l1=num[a].size(),l2=num[b].size();for(int i=0;i<l1;++i)if(gender[num[a][i]]==ga&&num[a][i]!=b)temp1.push_back(num[a][i]);//        for(int i=0;i<temp1.size();++i)
//            printf("%d ",temp1[i]);
//        printf("temp1\n");for(int i=0;i<l2;++i)if(gender[num[b][i]]==gb&&num[b][i]!=a)temp2.push_back(num[b][i]);//        for(int i=0;i<temp2.size();++i)
//            printf("%d ",temp2[i]);
//        printf("temp2\n");int t=0;l1=temp1.size(),l2=temp2.size();node ans[l1*l2+5];//        db2(l1,l2);for(int i=0;i<l1;++i){int flag[10010]={0};int l3=num[temp1[i]].size();
//            db1(l3);for(int j=0;j<l3;++j){
//                db3(j,temp1[i],num[temp1[i]][j]);flag[num[temp1[i]][j]]++;}for(int j=0;j<l2;++j){
//                db3(j,temp2[j],flag[temp2[j]]);if(flag[temp2[j]]==1)ans[t].a=temp1[i],ans[t].b=temp2[j],t++;}}sort(ans,ans+t,cmp);printf("%d\n",t);for(int i=0;i<t;++i)printf("%04d %04d\n",ans[i].a,ans[i].b);}#ifdef testclockid_t end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;printf("\n\n\n\n\n");cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位#endif //testreturn 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com