题目链接

https://www.patest.cn/contests/gplt/L2-028

思路

0.只处理被询问的情侣的亲密度,否则会超时

1.要注意输入数字要用字符串,还要标记性别 因为 输出-0 得到的数字是0

也就是说用int 型输入 是没有办法 辨别编号0的性别的

2.要注意被询问的情侣可能没有出现在照片当中。

输出的时候也要注意负号

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll; const double PI = acos(-1);
const double E = exp(1);
const double eps = 1e-6; const int INF = 0x3f3f3f3f;
const int maxn = 1e3 + 5;
const int MOD = 1e9 + 7; double ans[2][maxn]; map <int, int> M; int tran(char s[])
{
int len = strlen(s);
int i;
if (s[0] == '-')
i = 1;
else
i = 0;
int ans = 0;
for ( ; i < len; i++)
{
ans = ans * 10 + s[i] - '0';
}
if (s[0] == '-')
M[ans] = -1;
else
M[ans] = 1;
return ans;
} void print(int x, int y)
{
int a = abs(x);
int b = abs(y);
if (M[a] == -1)
printf("-%d ", a);
else
printf("%d ", a);
if (M[b] == -1)
printf("-%d\n", b);
else
printf("%d\n", b);
} int main()
{
int n, m;
scanf("%d%d", &n, &m);
vector <int> G[maxn];
int num, tot;
char s[10];
for (int i = 0; i < m; i++)
{
scanf("%d", &tot);
for (int j = 0; j < tot; j++)
{
scanf("%s", s);
num = tran(s);
G[i].pb(num);
}
}
int A, B;
CLR(ans);
scanf("%s", s);
A = tran(s);
scanf("%s", s);
B = tran(s);
vector <int>::iterator it;
double Max[2] = { 0.0, 0.0};
for (int i = 0; i < m; i++)
{
int flag[2] = { 0, 0 };
for (it = G[i].begin(); it != G[i].end(); it++)
{
if (*it == abs(A))
flag[0] = 1;
if (*it == abs(B))
flag[1] = 1;
if (flag[0] && flag[1])
break;
}
if (flag[0])
{
double k = 1.0 / G[i].size();
for (it = G[i].begin(); it != G[i].end(); it++)
{
if (*it != abs(A) && M[*it] * M[abs(A)] == -1)
{
ans[0][*it] += k;
}
Max[0] = max(Max[0], ans[0][*it]);
}
}
if (flag[1])
{
double k = 1.0 / G[i].size();
for (it = G[i].begin(); it != G[i].end(); it++)
{
if (*it != abs(B) && M[*it] * M[abs(B)] == -1)
{
ans[1][*it] += k;
}
Max[1] = max(Max[1], ans[1][*it]);
}
}
}
if (ans[0][abs(B)] == Max[0] && ans[1][abs(A)] == Max[1])
{
print(A, B);
}
else
{
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < n; j++)
{
if (ans[i][j] == Max[i] && M[abs(i? B:A)] * M[j] == -1)
{
print(i? B:A, j);
}
}
}
}
}

PAT 天梯赛 L2-028. 秀恩爱分得快 【数据处理】的更多相关文章

  1. 【PTA 天梯赛】L2-028 秀恩爱分得快(模拟)

    古人云:秀恩爱,分得快. 互联网上每天都有大量人发布大量照片,我们通过分析这些照片,可以分析人与人之间的亲密度.如果一张照片上出现了 K 个人,这些人两两间的亲密度就被定义为 1/K.任意两个人如果同 ...

  2. PAT L2-028 秀恩爱分得快

    https://pintia.cn/problem-sets/994805046380707840/problems/994805054698012672 古人云:秀恩爱,分得快. 互联网上每天都有大 ...

  3. L2-028 秀恩爱分得快(模拟)

    古人云:秀恩爱,分得快. 互联网上每天都有大量人发布大量照片,我们通过分析这些照片,可以分析人与人之间的亲密度.如果一张照片上出现了 K 个人,这些人两两间的亲密度就被定义为 1/K.任意两个人如果同 ...

  4. L2-028 秀恩爱分得快(25 分)

    古人云:秀恩爱,分得快. 互联网上每天都有大量人发布大量照片,我们通过分析这些照片,可以分析人与人之间的亲密度.如果一张照片上出现了 K 个人,这些人两两间的亲密度就被定义为 1/K.任意两个人如果同 ...

  5. 团体程序设计天梯赛 L2-028. 秀恩爱分得快

    1.输入-0(第一部分.第二部分),输出-02.只统计与两个人的亲密程度,否则超时 Data: 4 14 -0 1 -2 3-0 1 -0 1 ------ 4 1 3 1 -2 3-0 1 -0 1 ...

  6. pta l2-28(秀恩爱分得快)

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805054698012672 题意:给n个人,m张照片,在同一张 ...

  7. PAT天梯赛 L1-049 天梯赛座位分配

    题目链接:点击打开链接 天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情.为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i 所学校有 M[i] ...

  8. PAT天梯赛L3-007 天梯地图

    题目链接:点击打开链接 本题要求你实现一个天梯赛专属在线地图,队员输入自己学校所在地和赛场地点后,该地图应该推荐两条路线:一条是最快到达路线:一条是最短距离的路线.题目保证对任意的查询请求,地图上都至 ...

  9. PAT天梯赛练习题——L3-007. 天梯地图(多边权SPFA)

    L3-007. 天梯地图 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 本题要求你实现一个天梯赛专属在线地图,队员输入自己学校 ...

随机推荐

  1. centos使用yum安装gcc

    yum -y install gccyum -y install gcc-c++yum install make -- 或者yum groupinstall "Development Too ...

  2. 最好PHP开发工具Zend Studio 9.0.2的安装和使用

    摘要:Zend Studio是Zend Technologies开发的PHP语言集成开发环境(IDE),是公认最好的PHP开发工具.在5.5系列后,官方推出的Zend Studio都利用了Eclips ...

  3. 用PHP调用证件识别接口识别本地图片

    前置条件 在开始前,请作如下准备:1.学会用PHP输出“Hello World” 2.去聚合数据申请证件识别专用的KEY:https://www.juhe.cn/docs/api/id/153 操作步 ...

  4. java查看工具jhat-windows

    Analyzes the Java heap. This command is experimental and unsupported. Synopsis jhat [ options ] heap ...

  5. struts2获取ServletContext对象

      CreateTime--2017年9月7日09:24:40 Author:Marydon struts2获取ServletContext对象 需要导入: import javax.servlet. ...

  6. HBase笔记

    吴超 1.1 Hbase是Hadoop中的数据库,Hadoop还需要数据库吗?我们学的Hadoop是一个分布式的存储和计算的平台 为什么要在他上面建一个数据库呢,数据库是干什么的呢,数据库是一个管理系 ...

  7. DevOps企业实践与架构

    原文地址:http://www.sohu.com/a/112351816_355140 什么是DevOps及其误区 DevOps概念从2009年提出已有8个年头.可是在8年前的那个时候,为什么DevO ...

  8. WinForm搭载ScintillaNET时文本由于发生偏移被隐藏解决方案

    项目用ScintillaNet搭载到WinForm以满足文本编辑的需求,在用FindReplace.Scintilla.Text=“显示内容”输出文本内容的时候会碰到文本被WinForm边框隐藏的情况 ...

  9. Redis主从同步分析

    一.Redis主从同步原理1.1 Redis主从同步的过程配置好slave服务器连接的master后,slave会建立和master的连接,然后发送sync命令.无论是第一次同步建立的连接还是连接断开 ...

  10. 字符串== equals

    经常碰到比较字符串的题, eg: public class StringDemo{ private static final String MESSAGE = "taobao"; ...