Shark

题意:一个研究员观察了一条鲨鱼n天的运动,然后这条鲨鱼他只会往前走,不会回到去过的地方,现在有一个k,,如果鲨鱼当天游过的距离 >= k, 代表的鲨鱼在这天会前往下一个地点,现在求鲨鱼在每个停留的地点所待的时间是一样的,然后在上面那个情况下使得鲨鱼所待得地点数目最多,然后再地点数目的情况下保证K最小。

题解:从小到大处理元素,每次将k = 当前元素+1,因为只有k比一个元素大了才会有新的停留地点,然后对于所有出现过的元素鲨鱼都会在这个点停留,然后我们需要对每一段连续的停留片段计算出他的天数,然后check一下是否合法,我们可以用并查集将连续的片段合并记录长度来优化check,用set记录有几个片段,然后当片段数目 > 答案中的岛就check一下,如果成立,更新答案。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
const int N = 1e5+;
int n;
int pre[N];
int cnt[N];
int vis[N];
int ss[N];
struct Node{
int t;
int id;
}A[N];
bool cmp(Node x,Node y){
return x.t < y.t;
}
set<int>s ;
bool check(){
int ttt = *s.begin();
return ss[cnt[ttt]] == s.size();
}
int Find(int x){
if(x == pre[x]) return x;
return pre[x] = Find(pre[x]);
}
int main(){
scanf("%d", &n);
int ans = INF;
int len = ;
for(int i = ; i <= n; i++){
cnt[i] = ;
pre[i] = i;
}
for(int i = ; i <= n; i++){
scanf("%d", &A[i].t);
ans = min(ans,A[i].t+);
A[i].id = i;
}
sort(A+,A++n,cmp);
for(int i = ; i <= n; i++){
int now = A[i].id;
vis[now] = ;
int f = ;
if(now+ <= n && vis[now+]){
int t = Find(now), y = Find(now+);
pre[t] = y;
ss[cnt[y]]--;
cnt[y] += cnt[t];
ss[cnt[y]]++;
f = ;
}
if(now- >= && vis[now-]){
int t = Find(now), y = Find(now-);
if(f == ) s.erase(t),ss[cnt[t]]--;
ss[cnt[y]]--;
cnt[y] += cnt[t];
ss[cnt[y]]++;
pre[t] = y;
f = ;
}
if(f == ) s.insert(now), ss[cnt[now]]++;
if(s.size() > len && check()){
len = s.size();
ans = A[i].t+;
}
}
printf("%d", ans);
return ;
}

CodeForces 982 D Shark的更多相关文章

  1. 【矩阵乘法优化dp】[Codeforces 621E] Wet Shark and Blocks

    http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test 2 seconds ...

  2. Codeforces 612B. Wet Shark and Bishops 模拟

    B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  3. Codeforces 982 树边两端点计数偶数连通块 鲨鱼活动最小K最大location 扩展欧几里得方块内光线反射

    A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...

  4. CODEFORCEs 621E. Wet Shark and Blocks

    E. Wet Shark and Blocks time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. CodeForces 621C Wet Shark and Flowers

    方法可以转化一下,先计算每一个鲨鱼在自己范围内的数能被所给素数整除的个数有几个,从而得到能被整除的概率,设为f1,不能被整除的概率设为f2. 然后计算每相邻两只鲨鱼能获得钱的期望概率,f=w[id1] ...

  6. CodeForces 621B Wet Shark and Bishops

    记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include& ...

  7. CodeForces 621A Wet Shark and Odd and Even

    水题 #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #inclu ...

  8. codeforces 982 c

    给你一棵树 让你进行切割 问你最多能切多少刀   使得每个连通分量size都是偶数 思路:首先  要是有奇数个节点的话   那么不管你怎么切割  都会有一个连通分量的size是奇数 所以只有偶数的情况 ...

  9. Codeforces 621E Wet Shark and Block【dp + 矩阵快速幂】

    题意: 有b个blocks,每个blocks都有n个相同的0~9的数字,如果从第一个block选1,从第二个block选2,那么就构成12,问对于给定的n,b有多少种构成方案使最后模x的余数为k. 分 ...

随机推荐

  1. 如何确定FPGA电路中DDR4的Speed bin 是否兼容?

    原创 by DeeZeng DDR4 是否兼容,拿更快速度的DDR4,是否可以不改FPGA工程,直接换料就能直接用? 实际工作中,经常会碰到因为DDR3/4 或其他料件换料了,需要判断FPGA工程中I ...

  2. maven-assembly-plugin 进行打包

    maven-assembly-plugin使用描述(拷自 maven-assembly-plugin 主页) The Assembly Plugin for Maven is primarily in ...

  3. 用python实现九九乘法表输出-两种方法

    2019-08-05 思考过程:九九乘法表需要两层循环,暂且称之为内循环和外循环,因此需要写双层循环来实现. 循环有for和while两种方式. for循环的实现 for i in range(1,1 ...

  4. Xamarin 基础知识

    Xamarin 跨平台处理: C#: if (Device.OS == TargetPlatform.Android) { Code…… } else if (Device.OS == TargetP ...

  5. CSS3: @font-face 介绍与使用

    @font-face 是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,随着@font-face模块的出现,我们在Web的开发中使用字体不怕只能使用Web安全字体,你们当中或许有 ...

  6. 【POJ - 2385】Apple Catching(动态规划)

    Apple Catching 直接翻译了 Descriptions 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速 ...

  7. MVC+EF Core 完整教程20--tag helper详解

    之前我们有一篇:“动态生成多级菜单”,对使用Html Helper做了详细讲述,并且自定义了一个菜单的 Html Helper: https://www.cnblogs.com/miro/p/5541 ...

  8. jquery验证大全

    jQuery验证及限制 绑定键盘监听事件 $(document).on("keypress", ".txt-valid-len", function (e) { ...

  9. cs231n官方note笔记

    本文记录官方note中比较新颖和有价值的观点(从反向传播开始) 一 反向传播 1 “反向传播是一个优美的局部过程.在整个计算线路图中,每个门单元都会得到一些输入并立即计算两个东西:1. 这个门的输出值 ...

  10. c语言实现基本的数据结构(三) 栈

    #include <stdio.h> #include <tchar.h> #include <stdlib.h> #define StackSize 5 #def ...