把a[i], b[i]分开来排序

对应位置上的点连边

感性理解这是最小的

会连出若干个环

要使得若干个环连成大环

令a[i]向b[i - 1] 连边

易证一定能使图联通

感性理解这也是最小的

#include<cstdio>
#include<algorithm>
using namespace std;
const int P = 32767;
int n, x, y, z, F[1000005];
struct node
{
int val, id;
}a[1000005], b[1000005], e[1000005];
bool cmp(node a, node b)
{
return a.val < b.val;
}
int find(int x)
{
if (F[x] != x) F[x] = find(F[x]);
return F[x];
}
int main()
{
scanf("%d", &n);
scanf("%d%d%d%d%d", &a[1].val, &a[2].val, &x, &y, &z);
for (int i = 3; i <= n; i++) a[i].val = (1ll * x * a[i - 1].val + 1ll * y * a[i - 2].val + z) % P;
scanf("%d%d%d%d%d", &b[1].val, &b[2].val, &x, &y, &z);
for (int i = 3; i <= n; i++) b[i].val = (1ll * x * b[i - 1].val + 1ll * y * b[i - 2].val + z) % P;
for (int i = 1; i <= n; i++) a[i].id = b[i].id = i;
sort(a + 1, a + n + 1, cmp);
sort(b + 1, b + n + 1, cmp);
for (int i = 1; i <= n; i++) F[i] = i;
int ans = 0;
for (int i = 1; i <= n; i++)
{
int x = a[i].id, y = b[i].id;
int fx = find(x), fy = find(y);
F[fy] = fx;
ans = max(ans, a[i].val * a[i].val - b[i].val * b[i].val);
}
for (int i = 2; i <= n; i++) e[i - 1] = (node){a[i].val * a[i].val - b[i - 1].val * b[i - 1].val, i};
sort(e + 1, e + n, cmp);
for (int i = 1; i < n; i++)
{
int x = a[e[i].id].id, y = b[e[i].id - 1].id;
int fx = find(x), fy = find(y);
if (fx != fy)
{
F[fy] = fx;
ans = max(ans, e[i].val);
}
}
printf("%d\n", ans);
return 0;
}

  

2139: road的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  3. POJ 3204 Ikki's Story I - Road Reconstruction

    Ikki's Story I - Road Reconstruction Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 7 ...

  4. Codeforces #380 div2 C(729C) Road to Cinema

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. dp or 贪心 --- hdu : Road Trip

    Road Trip Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 29 ...

  6. HDU 1598 find the most comfortable road(最小生成树之Kruskal)

    题目链接: 传送门 find the most comfortable road Time Limit: 1000MS     Memory Limit: 32768 K Description XX ...

  7. 三分 --- CSU 1548: Design road

    Design road Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548 Mean: 目的:从(0,0)到 ...

  8. hdu 5861 Road 两棵线段树

    传送门:hdu 5861 Road 题意: 水平线上n个村子间有 n-1 条路. 每条路开放一天的价格为 Wi 有 m 天的操作,每天需要用到村子 Ai~Bi 间的道路 每条路只能开放或关闭一次. ( ...

  9. HDU4081 Qin Shi Huang's National Road System(次小生成树)

    枚举作为magic road的边,然后求出A/B. A/B得在大概O(1)的时间复杂度求出,关键是B,B是包含magic road的最小生成树. 这么求得: 先在原图求MST,边总和记为s,顺便求出M ...

随机推荐

  1. xfs管理2T以上大分区

    设置gpt硬盘 parted /dev/sdb (parted) mklabel gpt (parted) mkpart primary xfs 0 -1 (Ignore) (parted) quit ...

  2. windows10下 Jupyter 添加anaconda环境

    参考:https://blog.csdn.net/weixin_39934500/article/details/79138235 首先查看 anaconda下的环境信息  conda env lis ...

  3. IPV4基本知识介绍

    转自华为官网 1.1  介绍 定义 IPv4(Internet Protocol Version 4)协议族是TCP/IP协议族中最为核心的协议族.它工作在TCP/IP协议栈的网络层,该层与OSI参考 ...

  4. element-ui打包的坑爹之处 !!!必看三遍!!!

    最近笔者打包element-ui出现如下问题: ERROR in static/js/0.4cad92088cb8dc6e7afd.js from UglifyJs Unexpected token: ...

  5. leetcode:查找

    1.  word ladder 题目: Given two words (start and end), and a dictionary, find the length of shortest t ...

  6. Altium_Designer-PCB中布局元器件时的翻转问题

    这个问题是我在第一次对PCB元器件布局时发现的,当时我绘制好原理图生成PCB后,出现了这样一个情况: 在我反复尝试走线后,走好线发现很困难,最后我才想到如果能把这个器件反转一下问题不就都解决了吗!自己 ...

  7. SAP CRM和C4C的产品主数据price维护

    SAP CRM 点了Edit List之后,可以直接修改产品主数据的Price信息: C4C 在C4C的product administration工作中心里: 点击Edit按钮进入编辑模式,Pric ...

  8. 2017.10.28 针对Java Web应用中错误异常处理方法的运用

    针对Java Web应用中错误异常处理方法的运用 在javaweb中其异常都需要对Checked Exception之下的Exception进行继承,并且有选择地对发生的错误和异常进行处理.Java同 ...

  9. jQuery与Aiax应用

    Ajax(一部JavaScript和XML) 优势: ①不需要插件支持 ②优秀的用户体验:能在不刷新整个页面的前提下更新数据,这使得web应用程序能更为迅速地回应用户的操作. ③提高web程序的性能: ...

  10. Oracle中文乱码解决

    查看当前Oracle字符集 select userenv('language') from dual; USERENV('LANGUAGE') ---------------------------- ...