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. 个人项目-WC (java实现)

    一.Github地址:https://github.com/734635746/WC 二.PSP表格 PSP2.1 Personal Software Process Stages 预估耗时(分钟) ...

  2. 【JavaScript】JavaScript基本语法&知识点

    JavaScript: 是脚本语言:是一种解释性的语言(不需要编译) 作用: 让页面有具有动态效果 组成部分: ECMAScipt(核心),包含基本语法.变量.关键字.保留字.数据类型.语句.函数等 ...

  3. Java精通并发-Condition编程模式详解与分析

    继续上一次https://www.cnblogs.com/webor2006/p/11890688.html的Condition接口说明进行阅读: 上面这个程序会在之后手动来实现一下,说实话这种写法在 ...

  4. 201871010128-杨丽霞《面向对象程序设计(java)》第二周学习总结

    201871010128-杨丽霞<面向对象程序设计(java)>第二周学习总结 项目 内容 这个作业属于哪个课程 <https://www.cnblogs.com/nwnu-daiz ...

  5. wordpress列表页如果文章没有缩略图就显示默认图片

    有时我们在设计wordpress模板时需要考虑是否有特色图,在分类页上如果一些文章有缩略图一些没有那就有点参差不齐不美观,有没办法设置如果没有文章缩略图则自动显示默认图呢?可以的,随ytkah一起来看 ...

  6. 03-C#笔记-数据类型

    --- # 1 数据类型 --- ## 1 和C++不同的数据类型: byte: 8位,0~255 decimal:范围大于double,128位 sbyte: 8位,-128~127 uint 32 ...

  7. Pandas | 04 Panel 面板

    面板(Panel)是3D容器的数据.面板数据一词来源于计量经济学,部分源于名称:Pandas - pan(el)-da(ta)-s. 3轴(axis)这个名称旨在给出描述涉及面板数据的操作的一些语义. ...

  8. Checking Types Against the Real World in TypeScript

    转自:https://www.olioapps.com/blog/checking-types-real-world-typescript/ This is a follow-up to Type-D ...

  9. 7-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案安全篇(GPRS模块SSL连接MQTT)

    6-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案安全篇(Wi-Fi模块SSL连接MQTT) 由于GPRS是直接和GPRS基站进行连接,其实对于GPRS而言,即使不加 ...

  10. 3.shell编程-文件查找之find命令

    3.1.语法格式 find [路劲][选项][操作] 选项参数对照表 3.2.-name 查找/etc/目录下以.conf结尾的文件 find /etc/ -name "*.conf&quo ...