【链接】 我是链接,点我呀:)

【题意】

让你根据冒泡排序的规则
建立一张图
问你这张图的最大独立子集的大小

【题解】

考虑a[i]会和哪些点连边?
必然是在a[i]左边且比它大的数字以及在a[i]右边比它小的数字
(根据冒泡排序的原理)
所以如果选择了a[i]就不能再选择它左边比它大的数字或者在a[i]右边比它小的数字了
(因为肯定有连边)
那么可以选择什么呢?
必然是它左边比它小的数字以及在它右边比它大的数字
(肯定和它们没有连边)

那么想一想

选出来的每个数字都要满足这样的特点

不就是一个上升序列吗?

所以选择一个最长上升序列就ok了!

用二分优化一下就好

mi[i]表示长度为i的最长上升子序列的最后一个元素的最小值

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)1e5;
static class Task{ int n;
int a[];
int mi[],R; public void solve(InputReader in,PrintWriter out) {
n = in.nextInt();
a = new int[N+10];
mi = new int[N+10]; for (int i = 1;i <= n;i++) a[i] = in.nextInt();
R = 0;
for (int i = 1;i <= n;i++) {
int l = 1,r = R,temp = 0;
while (l<=r) {
int mid = (l+r)>>1;
if (mi[mid]<=a[i]) {
temp = mid;
l = mid + 1;
}else {
r = mid - 1;
}
}
if (mi[temp+1]==0) {
R = temp+1;
mi[temp+1] = a[i];
}else {
mi[temp+1] = Math.min(mi[temp+1], a[i]);
}
}
out.println(R);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 340D】Bubble Sort Graph的更多相关文章

  1. 【codeforces 716D】Complete The Graph

    [题目链接]:http://codeforces.com/problemset/problem/716/D [题意] 给你一张图; 这张图上有一些边的权值未知; 让你确定这些权值(改成一个正整数) 使 ...

  2. 【39.77%】【codeforces 724B】Batch Sort

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【Codeforces 1009D】Relatively Prime Graph

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 1000以内就有非常多组互质的数了(超过1e5) 所以,直接暴力就行...很快就找完了 (另外一开始头n-1条边找1和2,3...n就好 [代 ...

  4. Bubble Sort Graph CodeForces - 340D || 最长不下降/上升子序列

    Bubble Sort Graph CodeForces - 340D 题意: 给出一个n个数的数列,建一个只有n个结点没有边的无向图,对数列进行冒泡排序,每交换一对位置在(i,j)的数在点i和点j间 ...

  5. codeforces 340D Bubble Sort Graph(dp,LIS)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud  Bubble Sort Graph Iahub recently has lea ...

  6. Codeforces Round #198 (Div. 2) D. Bubble Sort Graph (转化为最长非降子序列)

    D. Bubble Sort Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  8. 【Azure Developer】使用Microsoft Graph API 批量创建用户,先后遇见的三个错误及解决办法

    问题描述 在先前的一篇博文中,介绍了如何使用Microsoft Graph API来创建Azure AD用户(博文参考:[Azure Developer]使用Microsoft Graph API 如 ...

  9. 【codeforces 755E】PolandBall and White-Red graph

    [题目链接]:http://codeforces.com/contest/755/problem/E [题意] 给你n个节点; 让你在这些点之间接若干条边;构成原图(要求n个节点都联通) 然后分别求出 ...

随机推荐

  1. .NET平台下Redis使用(三)【ServiceStack.Redis学习】

    MVC4项目下对redis进行增删该查 Models文件下实体类: public class Book { public string BookName {get;set;} public strin ...

  2. bzoj1023 [SHOI2008]cactus仙人掌图 & poj3567 Cactus Reloaded——求仙人掌直径

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1023    http://poj.org/problem?id=3567 仙人掌!直接模仿 ...

  3. 41. extjs--combobox下拉列表的triggerAction

    转自:https://icrwen.iteye.com/blog/939247 一般combobox的store先load加载数据,然后combobox的mode设置为local,则不会每次下拉列表都 ...

  4. [Swift通天遁地]三、手势与图表-(11)制作雷达图表更加形象表示各个维度的情况

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. easyui DatagrId 的实例讲解

    下面是代码实现 @{    ViewBag.Title = "人员查找";    ViewBag.LeftWidth = "200px";    ViewBag ...

  6. Android中有四大组件的简单总结

    Android四大基本组件分别是Activity,Service服务,Content Provider内容提供者,BroadcastReceiver广播接收器. 一:了解四大基本组件 Activity ...

  7. 大话设计模式--DI(依赖注入)

    1.背景 想象一个场景:有个功能通过某个参数决定了路由到不同的方法上或者几个方法模块可以自由搭配,咋办?一般人会对每个方法写一个helper(比如SendMessageForEmail.SendMes ...

  8. spring编程框架

    spring boot, spring data, spring framework spring / spring boot @Profile('prod'|'dev'|'other')(伴随@Be ...

  9. 【译】x86程序员手册00 - 翻译起因

    从上一次学习MIT的操作系统课程又过去了一年.上次学习并没有坚持下去.想来虽有种种原因,其还在自身无法坚持罢了.故此次再鼓起勇气重新学习,发现课程都已由2014改版为2016了.但大部分内容并没有改变 ...

  10. N的阶乘末尾有多少个零?

    在创联ifLab的招新问答卷上看到这么一题 核心问题是: 求N!(N的阶乘)的末尾有多少个零? 由于在N特别大的时候强行算出N!是不可能的,所以肯定要另找方法解决了. 首先,为什么末尾会有0?因为2* ...