2139: road
把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的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- POJ 3204 Ikki's Story I - Road Reconstruction
Ikki's Story I - Road Reconstruction Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 7 ...
- 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 ...
- dp or 贪心 --- hdu : Road Trip
Road Trip Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 29 ...
- HDU 1598 find the most comfortable road(最小生成树之Kruskal)
题目链接: 传送门 find the most comfortable road Time Limit: 1000MS Memory Limit: 32768 K Description XX ...
- 三分 --- CSU 1548: Design road
Design road Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548 Mean: 目的:从(0,0)到 ...
- hdu 5861 Road 两棵线段树
传送门:hdu 5861 Road 题意: 水平线上n个村子间有 n-1 条路. 每条路开放一天的价格为 Wi 有 m 天的操作,每天需要用到村子 Ai~Bi 间的道路 每条路只能开放或关闭一次. ( ...
- HDU4081 Qin Shi Huang's National Road System(次小生成树)
枚举作为magic road的边,然后求出A/B. A/B得在大概O(1)的时间复杂度求出,关键是B,B是包含magic road的最小生成树. 这么求得: 先在原图求MST,边总和记为s,顺便求出M ...
随机推荐
- C#设计模式--工厂模式(创建型模式)
一.简单工厂模式(UML类图): 核心类代码: public class Calc { public double NumberA { get; set; } public double Number ...
- SharePoint 2010 列表查阅项栏的formfield控件对象取值
开发的时候想当然的认为主表解析出来就是一个dropdownlist,可是在大数据测试的时候,发现有情况. 首先创建一个子列表:DetailList,并添加19条数据: 创建主列表:MainList,并 ...
- [转]linux tcp/ip调优
LINUX tcp/ip性能调优 On 2011年03月15日, in linux, tips, by netoearth 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接 ...
- IDEA中git的配置与使用
IDEA中git的配置与使用 1.介绍 git是目前非常流行的版本管理管理软件,因其具有分布式特点,越来越受到企业的欢迎.IDEA作为一款优秀的开发软件,其内部也提供了对git的支持. 2.下载并安装 ...
- April 16 2017 Week 16 Sunday
Happiness is a way station between too much and too little. 幸福就是刚刚好. I don't want to talk about it a ...
- reactjs--父组件调用子组件的内部方法(转载)
reactjs--父组件调用子组件的内部方法 发表于2016/10/11 9:21:37 965人阅读 1.引入相关js <script src="js/react.js" ...
- Sublime插件支持Sass编译和Babel解析ES6 & .sublime-build文件初探(转载自imwtr)
原文请看:http://www.cnblogs.com/imwtr/p/6010550.html 用Sublime Text蛮久了,配置配来配去的,每次换电脑都得重头再配过,奈何人老了脑子不中用了 ...
- framework7滑动删除列表触发chrome 报错解决办法
使用 <div class="list-block"> <ul> <li class="swipeout"> <div ...
- 进程管理—进程描述符(task_struct)
http://blog.csdn.net/qq_26768741/article/details/54348586 当把一个程序加载到内存当中,此时,这个时候就有了进程,关于进程,有一个相关的叫做进程 ...
- 模拟停车POJ(3505)
题目链接:http://poj.org/problem?id=3505 解题报告: #include <stdio.h> #include <iostream> #includ ...