PAT甲级-1139 First Contact (30 分)
发布日期:2022-02-10 08:11:03 浏览次数:19 分类:技术文章

本文共 1374 字,大约阅读时间需要 4 分钟。

题目:
分析:模拟,排序,本题性别为女时,负号只是一个标志,若出现了-2200 则不可能在出现2200,因此也可以用int来,不需要字符串(若使用map来遍历,会超时)

AC代码(下面还有个超时代码,使用map的):

#include 
#include
#include
#include
#include
#include
#include
using namespace std;int n,m,k;int road[10001][10001];int gend[10001];map
>ma;struct Node{ int a,b;};vector
ans;int cmp(Node x,Node y){ if(x.a != y.a) return x.a
>a>>b; if(a[0] == '-') gend[abs(stoi(a))] = 0; else gend[abs(stoi(a))] = 1; if(b[0] == '-') gend[abs(stoi(b))] = 0; else gend[abs(stoi(b))] = 1; int x = abs(stoi(a)); int y = abs(stoi(b)); road[x][y] = road[y][x] = 1; ma[x].push_back(y); ma[y].push_back(x); } scanf("%d",&k); for(int i = 0;i

超时代码

#include
#include
#include
#include
#include
#include
#include
using namespace std;int n,m,k;map
>frd;map
>ma;map
gender;struct node{ int a,b;};int cmp(node x,node y){ if(x.a != y.a) return x.a < y.a; return x.b
>n>>m; for(int i = 0 ; i < m ;i++) { string a,b; cin>>a>>b; if(a[0] == '-')gender[a] = 1; else gender[a] = 0; if(b[0] == '-')gender[b] = 1; else gender[b] = 0; ma[a][b] = 1; ma[b][a] = 1; frd[a].push_back(b); frd[b].push_back(a); } cin>>n; for(int i = 0 ; i < n ;i++) { string a,b;cin>>a>>b; int cnt = 0; node ans[100001]; for(int i = 0 ; i < frd[a].size();i++) { for(int j = 0 ; j

转载地址:https://blog.csdn.net/qq_43567222/article/details/114365465 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:PAT甲级-1130 Infix Expression (25 分)
下一篇:PAT甲级-1140 Look-and-say Sequence (20 分)

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月07日 16时18分56秒