把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. X-Cart-5.3.1.4 (Ubuntu 16.04)

    平台: Ubuntu 类型: 虚拟机镜像 软件包: x-cart-5.3.1.4 commercial ecommerce open-source x-cart 服务优惠价: 按服务商许可协议 云服务 ...

  2. 笨办法学Python(三十七)

    习题 37: 复习各种符号 现在该复习你学过的符号和 python 关键字了,而且你在本节还会学到一些新的东西.我在这里所作的是将所有的 Python 符号和关键字列出来,这些都是值得掌握的重点. 在 ...

  3. myeclipse 10 创建webservice

    java 快捷创建webservice 收集一下,方便一下查阅 详情去看一下这个老哥,里面写得非常详细: http://hyan.iteye.com/ -- http://www.cnblogs.co ...

  4. Sublime Text3 + Markdown + 实时预览

    Sublime Text3是一款给力的文本编辑器,通过安装插件可以编辑Markdown文本,在编辑Markdown文本的同时可以实时预览编辑效果. 安装准备: 找到菜单栏:Preferences → ...

  5. iRecognizer号码扫描开发实录

    iRecognizer——这是一款可以帮助你快速扫描获得印刷体数字的软件 现已上架 腾讯应用宝,酷安 提供的功能:扫一扫(相册或当场扫描),获得电话号码,之后就可以拨打或者发送短信,自动复制到剪贴板, ...

  6. Javascript作业—取字符串的第一个只出现一次的字母

    js作业 取字符串第一个只出现一次的字母 <script type='text/javascript'> //取a-z字符串中第一个只出现一次的字母 function firstUniqu ...

  7. vue项目里的日期格式化(摘录)

    export function formatDate (date, fmt) { if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (date. ...

  8. IOS 获取.plist文件的数据

      @property (nonatomic,strong) NSArray *apps; //获取.plist数据 /**获取plist文件的数组数据*/ -(NSArray *)apps{ if( ...

  9. 解决Jenkins的错误“The Server rejected the connection: None of the protocols were accepted”

    1. 配置节点,配置好节点后,在节点机上运行已下载文件,双击执行,提示"The Server rejected the connection: None of the protocols w ...

  10. 【转】你是不是也被Android Private Libraries、Referenced Libraries、android Dependency搞晕了~~

    一.v4.v7.v13的作用和用法 1.Android Support V4, V7, V13是什么? 本质上就是三个java library. 2.为什么要有support库?   是为了解决软件的 ...