https://pintia.cn/problem-sets/994805342720868352/problems/994805344776077312

其实这道题目不难,但是有很多坑点!

首先数据是性别+id,id不是数字!

输出的时候必须前面补0,

另外什么自己和自己连边,重复的边都要注意,

更注意的是 -0000,这个数据,不能用int来读,我艹

#include <iostream>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <string.h> using namespace std;
int n;
int m; struct Node
{
int value;
int next; }edge[200005]; struct Answer
{
int a;
int b; }res[200005]; int Compare(Answer a,Answer b)
{
if(a.a == b.a)
return a.b < b.b;
return a.a < b.a;
} map<pair<int,int>,int> dic;
map<pair<int,int>,int> dic2; int pos;
int head[10005]; int gender[10005]; void Add(int x,int y)
{
edge[pos].value = y;
edge[pos].next = head[x];
head[x] = pos++;
} int tag; void fun(int x,int y)
{
tag=0; dic2.clear(); int i = head[x]; int a[305];
int j=0; while(i != -1)
{
if(gender[edge[i].value] == gender[x]
&& edge[i].value != y && edge[i].value!=x) {
a[j++] = edge[i].value;
} i = edge[i].next;
} i = head[y];
int b[305];
int k=0; while(i!=-1)
{
if(gender[edge[i].value] == gender[y]
&& edge[i].value != x && edge[i].value!=y) {
b[k++] = edge[i].value;
} i = edge[i].next;
} for(int p=0;p<j;p++)
{
for(int q=0;q<k;q++)
{
if(a[p]==b[q])
continue; if(dic[make_pair(a[p],b[q])]==1)
{
Answer s;
s.a = a[p];
s.b = b[q];
res[tag++] = s;
}
}
} sort(res,res+tag,Compare); printf("%d\n",tag); for(int i=0;i<tag;i++)
{ printf("%04d %04d\n",res[i].a,res[i].b);
} } int main()
{
scanf("%d%d",&n,&m); memset(head,-1,sizeof(head));
pos=0; string xx,yy;
int x;
int y;
for(int i=0;i<m;i++)
{
cin>>xx>>yy; x = atoi(xx.c_str());
y = atoi(yy.c_str()); if(x<0 || xx[0]=='-')
gender[abs(x)]=-1;
else
gender[x]=1; if(y<0 || yy[0]=='-')
gender[abs(y)]=-1;
else
gender[y]=1; x = abs(x);
y = abs(y); if(dic[make_pair(x,y)]==1)
continue; Add(x,y);
Add(y,x); dic[make_pair(x,y)]=1;
dic[make_pair(y,x)]=1;
} int k;
scanf("%d",&k); for(int i=0;i<k;i++)
{
scanf("%d%d",&x,&y); x = abs(x);
y = abs(y); fun(x,y);
}
return 0;
}

PTA 甲级 1139的更多相关文章

  1. PTA甲级1094 The Largest Generation (25分)

    PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...

  2. pat甲级1139

    1139 First Contact(30 分) Unlike in nowadays, the way that boys and girls expressing their feelings o ...

  3. PTA甲级B1061 Dating

    目录 B1061 Dating (20分) 题目原文 Input Specification: Output Specification: Sample Input: Sample Output: 生 ...

  4. PAT甲级1139 First Contact

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805344776077312 题意: 有m对朋友关系,每个人用4为数 ...

  5. PTA甲级—链表

    1032 Sharing (25分) 回顾了下链表的基本使用,这题就是判断两个链表是否有交叉点. 我最开始的做法就是用cnt[]记录每个节点的入度,发现入度为2的节点即为答案.后来发现这里忽略了两个链 ...

  6. PTA甲级—STL使用

    1051 Pop Sequence (25分) [stack] 简答的栈模拟题,只要把过程想清楚就能做出来. 扫描到某个元素时候,假如比栈顶元素还大,说明包括其本身的在内的数字都应该入栈.将栈顶元素和 ...

  7. PTA甲级—数学

    1.简单数学 1008 Elevator (20分) 模拟题 #include <cstdio> #include <cstring> #include <string& ...

  8. PTA甲级—常用技巧与算法

    散列 1078 Hashing (25 分) Quadratic probing (with positive increments only) is used to solve the collis ...

  9. PTA 1139 1138 1137 1136

    PAT 1139 1138 1137 1136 一个月不写题,有点生疏..脑子跟不上手速,还可以啦,反正今天很开心. PAT 1139 First Contact 18/30 找个时间再修bug 23 ...

随机推荐

  1. java 使用tess4j实现OCR的最简单样例

    网上很多教程没有介绍清楚tessdata的位置,以及怎么配置,并且对中文库的描述也存在问题,这里介绍一个最简单的样例. 1.使用maven,直接引入依赖,确保你的工程JDK是1.8以上 <dep ...

  2. SQLServer2017自动备份数据库

    本文截图来源: 地址一:https://blog.csdn.net/u010944388/article/details/86674078 地址二:https://www.cnblogs.com/ja ...

  3. Django ORM (二) 增加操作

    数据库表结构生成完毕后,可以使用工具连接上去 在 app01_author 表创建基础记录 在 app01_publisher 表创建基础记录 添加 data_oper 方法 在 urls.py 文件 ...

  4. 安装centos6.10时,安装完成重启报错error 15,file not found

    今天在一台老式联想服务器上安装centos6.10操作系统,安装完成,重启时,出现报错 error 15, file not found...... 在百度上搜索到进grub编辑,可还是无法解决问题, ...

  5. istio部署-helm

    参考 istio/istio istio/Kubernetes Customizable Install with Helm Istio安装参数介绍 1. Istio Chart 目录结构 PATH: ...

  6. 【Linux】bat文件如何执行

    绝对路径,"/home/myDir/xxx.bat" OR 所在的目录,:"./xxx.bat".

  7. [codevs1566]染色

    题目描述 Description 给定一棵有n个节点的无根树和m个操作,操作有2类: 1.将节点a到节点b路径上所有点都染成颜色c: 2.询问节点a到节点b路径上的颜色段数量(连续相同颜色被认为是同一 ...

  8. Pandas | 20 级联

    Pandas提供了各种工具(功能),可以轻松地将Series,DataFrame和Panel对象组合在一起. pd.concat(objs,axis=0,join='outer',join_axes= ...

  9. ABP 依赖报错

    一般是自己写的Service 没有实现IApplicationService,和没有继承ApplicationService

  10. .NETCore_项目启动设置域名以及端口

    //第一种方式就是启动是一个命令窗口 public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.C ...