题目链接

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. lampp、xampp安装文档

    第一步:去官网 看这个介绍http://www.apachefriends.org/zh_cn/xampp-linux.html#1677 第二步:下载安装包 2.1 要区分Linux是32位还是64 ...

  2. 2017.2.28 activiti实战--第五章--用户与组及部署管理(三)部署流程及资源读取

    学习资料:<Activiti实战> 第五章 用户与组及部署管理(三)部署流程及资源读取 内容概览:如何利用API读取已经部署的资源,比如读取流程定义的XML文件,或流程对应的图片文件. 以 ...

  3. 转:Java 自动装箱与拆箱(Autoboxing and unboxing)

    转: http://www.cnblogs.com/danne823/archive/2011/04/22/2025332.html 什么是自动装箱拆箱 基本数据类型的自动装箱(autoboxing) ...

  4. HTML字体对应word字体

    42磅对应初号. 36磅对应小初. 26磅对应一号. 24磅对应小一号. 22磅对应二号. 18磅对应小二号. 16磅对应三号. 15磅对应小三号. 14磅对应四号. 12磅对应小四号. 10.5磅对 ...

  5. Robot framework 引入 Selenium2Library 类库:

    在用robotframework-selenium2library做web自动化测试时候,首先要将Selenium2Library导入到Test Suite中,在导入Selenium2Library时 ...

  6. sprint3 【每日scrum】 TD助手站立会议第六天

    站立会议 组员 昨天 今天 困难 签到 刘铸辉 (组长) 在添加日程类型处添加了选择闹钟间隔多长时间相应,并写了闹钟运行的类 在日历各个事件上都增加闹钟显示,并将数据传递给日程和时间表 感觉跟楠哥在设 ...

  7. jquery垂直滚动插件一个参数用于设置速度,兼容ie6

    利用外层的块级元素负外边距来滚动 1.使用 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://ww ...

  8. js 中的 prototype 和 constructor

    var a=function(){ this.msg="aa"; } a.prototype.say=function(){ alert('this is say');} 1.只有 ...

  9. mysql忘记root密码且忘了安装目录如何修改root密码

    问题背景 很久之前在本机上安装mysql,也没用过(主要是用Oracle),导致root密码忘记.更严重的是,连自己的安装目录都忘记了. 遇到的问题 1.在任务管理器可以找到mysql的服务已经起来, ...

  10. Proving Equivalences (hdu 2767 强联通缩点)

    Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...