liaoliao的四连做第二弹

liaoliao四连做第一弹


1.bzoj3211: 花神游历各国

由于$10^9$以内的数最多只会被开方$10$次,所以我们可以用线段树维护然后剪枝..

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
const LL Maxn = 100010;
LL p[Maxn][31], nochange[Maxn][31];
LL sum[Maxn*4], la[Maxn*4]; bool isone[Maxn*4];
LL n, m;
void bulid_tree ( LL now, LL L, LL R ){
    if ( L < R ){
        LL mid = ( L + R ) >> 1, lc = now*2, rc = now*2+1;
        bulid_tree ( lc, L, mid );
        bulid_tree ( rc, mid+1, R );
        sum[now] = sum[lc]+sum[rc];
        la[now] = 0;
        if ( isone[lc] && isone[rc] ) isone[now] = true;
    }
    else {
        sum[now] = p[L][0]-p[L-1][0];
        la[now] = 0;
        if ( sum[now] <= 1 ) isone[now] = true;
    }
}
void push_down ( LL now, LL L, LL R ){
    LL mid = ( L + R ) >> 1, lc = now*2, rc = now*2+1;
    if ( la[now] >= 0 ){
        la[lc] = la[rc] = la[now];
        sum[lc] = p[mid][la[lc]]-p[L-1][la[lc]];
        if ( nochange[mid][la[lc]]-nochange[L-1][la[lc]] == mid-L+1 ) isone[lc] = true;
        sum[rc] = p[R][la[rc]]-p[mid][la[rc]];
        if ( nochange[R][la[rc]]-nochange[mid][la[rc]] == R-mid ) isone[rc] = true;
    }
}
void change ( LL now, LL L, LL R, LL l, LL r ){
    if ( isone[now] ) return;
    if ( L == l && R == r && la[now] != -1 ){
        la[now] ++;
        sum[now] = p[R][la[now]]-p[L-1][la[now]];
        if ( nochange[R][la[now]]-nochange[L-1][la[now]] == (R-L+1) ) isone[now] = true;
        return;
    }
    push_down ( now, L, R );
    LL mid = ( L + R ) >> 1, lc = now*2, rc = now*2+1;
    if ( r <= mid ) change ( lc, L, mid, l, r );
    else if ( l > mid ) change ( rc, mid+1, R, l, r );
    else change ( lc, L, mid, l, mid ), change ( rc, mid+1, R, mid+1, r );
    sum[now] = sum[lc]+sum[rc];
    if ( la[lc] == la[rc] ) la[now] = la[lc]; else la[now] = -1;
    if ( isone[lc] && isone[rc] ) isone[now] = true;
}
LL query ( LL now, LL L, LL R, LL l, LL r ){
    if ( L == l && R == r ) return sum[now];
    push_down ( now, L, R );
    LL mid = ( L + R ) >> 1, lc = now*2, rc = now*2+1;
    if ( r <= mid ) return query ( lc, L, mid, l, r );
    else if ( l > mid ) return query ( rc, mid+1, R, l, r );
    else return query ( lc, L, mid, l, mid ) + query ( rc, mid+1, R, mid+1, r );
}
int main (){
    LL i, j, k;
    scanf ( "%lld", &n );
    for ( i = 1; i <= n; i ++ ){
        scanf ( "%lld", &p[i][0] );
        if ( p[i][0] <= 1 ) nochange[i][0] = 1;
        for ( j = 1; j <= 10; j ++ ){
            p[i][j] = (LL)sqrt(p[i][j-1]);
            if ( p[i][j] <= 1 ) nochange[i][j] = 1;
        }
    }
    for ( j = 0; j <= 10; j ++ ){
        for ( i = 1; i <= n; i ++ ) p[i][j] += p[i-1][j], nochange[i][j] += nochange[i-1][j];
    }
    bulid_tree ( 1, 1, n );
    scanf ( "%lld", &m );
    for ( i = 1; i <= m; i ++ ){
        LL fl, l, r;
        scanf ( "%lld%lld%lld", &fl, &l, &r );
        if ( fl == 1 ){
            printf ( "%lld\n", query ( 1, 1, n, l, r ) );
        }
        else {
            change ( 1, 1, n, l, r );
        }
    }
    return 0;
}

  


2.bzoj4240: 有趣的家庭菜园

考虑一个贪心策略,从小到大移动,小的数肯定放两边(哪边近放哪边)

那么对于某个数能够影响他的也就只有比他大的数了

然后就从大到小插入然后树状数组判断一下就好了..

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
using namespace std;
const LL Maxn = 300010;
struct node {
    int x, pos;
}list[Maxn];
bool cmp ( node x, node y ){ return x.x > y.x; }
LL sum[Maxn], n;
LL lowbit ( LL x ){ return x & (-x); }
void add ( LL x ){ while ( x <= n ){ sum[x] ++; x += lowbit (x); } }
LL query ( LL x ){ LL ret = 0; while ( x > 0 ){ ret += sum[x]; x -= lowbit (x); } return ret; }
LL _min ( LL x, LL y ){ return x < y ? x : y; }
int main (){
    LL i, j, k;
    scanf ( "%lld", &n );
    for ( i = 1; i <= n; i ++ ) scanf ( "%lld", &list[i].x ), list[i].pos = i;
    sort ( list+1, list+n+1, cmp );
    memset ( sum, 0, sizeof (sum) );
    LL ans = 0;
    LL num = 1;
    for ( i = 1; i <= n; i ++ ){
        if ( list[i].x != list[i-1].x ){
            while ( num < i ) add (list[num].pos), num ++;
        }
        LL s = query (list[i].pos);
        ans += _min ( s, num-s-1 );
    }
    printf ( "%lld\n", ans );
    return 0;
}

  


3.bzoj3232: 圈地游戏

二分答案,然后用网络流判断,是一个比较经典的最小割模型..

像这种小数流量的,可以先把这个数扩大$10^6$最后再缩小..

听说这种做法叫做分数规划(雾)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#define LL long long
using namespace std;
const LL Maxn = 55;
const LL Maxm = 55*55;
const LL inf = 0x7fffffff;
struct node {
    LL y, next, opp; LL c;
}a[Maxm*20]; LL first[Maxm], len;
void ins ( LL x, LL y, LL c ){
    len ++; LL k1 = len;
    a[len].y = y; a[len].c = c;
    a[len].next = first[x]; first[x] = len;
    len ++; LL k2 = len;
    a[len].y = x; a[len].c = 0;
    a[len].next = first[y]; first[y] = len;
    a[k1].opp = k2;
    a[k2].opp = k1;
}
LL n, m;
LL st, ed, h[Maxm];
LL getnum ( LL x, LL y ){ return (x-1)*m+y; }
LL map[Maxn][Maxn];
LL row[Maxn][Maxn], col[Maxn][Maxn];
LL _min ( LL x, LL y ){ return x < y ? x : y; }
LL dfs ( LL x, LL flow ){
    if ( x == ed ) return flow;
    LL delta = 0;
    for ( LL k = first[x]; k; k = a[k].next ){
        LL y = a[k].y;
        if ( h[y] == h[x]+1 && a[k].c > 0 && flow-delta > 0 ){
            LL minf = dfs ( y, _min ( a[k].c, flow-delta ) );
            delta += minf;
            a[k].c -= minf;
            a[a[k].opp].c += minf;
        }
    }
    if ( delta == 0 ) h[x] = -1;
    return delta;
}
bool bfs (){
    queue <LL> q;
    memset ( h, -1, sizeof (h) );
    q.push (st); h[st] = 0;
    while ( !q.empty () ){
        LL x = q.front (); q.pop ();
        for ( LL k = first[x]; k; k = a[k].next ){
            LL y = a[k].y;
            if ( h[y] == -1 && a[k].c > 0 ){
                h[y] = h[x]+1;
                q.push (y);
            }
        }
    }
    return h[ed] > 0;
}
int main (){
    LL i, j, k;
    scanf ( "%lld%lld", &n, &m );
    LL sum = 0;
    for ( i = 1; i <= n; i ++ ) for ( j = 1; j <= m; j ++ ){ scanf ( "%lld", &map[i][j] ); sum += map[i][j]; }
    sum *= 1e6;
    for ( i = 1; i <= n+1; i ++ ) for ( j = 1; j <= m; j ++ ) scanf ( "%lld", &row[i][j] );
    for ( i = 1; i <= n; i ++ ) for ( j = 1; j <= m+1; j ++ ) scanf ( "%lld", &col[i][j] );
    LL l = 0, r = 100*1e6, ret;
    st = 0; ed = n*m+1;
    while ( l <= r ){
        LL mid = (l+r)>>1;
        len = 0; memset ( first, 0, sizeof (first) );
        for ( i = 1; i <= n; i ++ ){
            for ( j = 1; j <= m; j ++ ){
                LL x = getnum (i,j);
                if ( i == 1 ) ins ( st, x, row[1][j]*mid );
                if ( i == n ) ins ( st, x, row[n+1][j]*mid );
                if ( j == 1 ) ins ( st, x, col[i][1]*mid );
                if ( j == m ) ins ( st, x, col[i][m+1]*mid );
                ins ( x, ed, map[i][j]*1e6 );
                LL ii = i, jj = j+1;
                if ( ii >= 1 && ii <= n && jj >= 1 && jj <= m ){
                    ins ( x, getnum(ii,jj), col[i][j+1]*mid );
                    ins ( getnum(ii,jj), x, col[i][j+1]*mid );
                }
                ii = i+1; jj = j;
                if ( ii >= 1 && ii <= n && jj >= 1 && jj <= m ){
                    ins ( x, getnum(ii,jj), row[i+1][j]*mid );
                    ins ( getnum(ii,jj), x, row[i+1][j]*mid );
                }
            }
        }
        LL delta = 0;
        while ( bfs () ){
            delta += dfs ( st, inf*1e6 );
        }
        if ( sum-delta > 0 ){ ret = mid; l = mid+1; }
        else r = mid-1;
    }
    printf ( "%.3lf\n", (double)ret/1e6 );
    return 0;
}

  


4.bzoj3162: 独钓寒江雪

先找重心,因为重心肯定是刚好对应的(如果有两个重心就新建一个重心练到这两个点然后再乱搞..)

那么剩下的肯定只有是在交换子树下才有可能同形异构..

这个东西就是一个可重复排列..

代码先挖个坑..

时间: 2024-07-31 19:33:30

liaoliao的四连做第二弹的相关文章

C/C++中容器vector使用方法&lt;第二弹&gt;

此文总结常用vector操作,是前一篇的续作!只有代码,详细请看代码中的注释.出于反爬虫的目的,你不是在http://blog.csdn.net/zhanh1218上看到的,肯定不是最新最全的. /********************************************************************* * file_name: vector_test.cpp * * Created on: 2014年6月28日 下午3:34:23 * Author: The_T

《我与希乐仑》第二弹

致徐敏: 如果你觉得我的这篇报道侵害了你和贵公司的权益,你可以上法院告我,但我说的都是事实,不怕你告,有事找我律师,谢谢! 我是希乐仑科技发展(上海)有限公司前员工,曾经为希乐仑立下汗马功劳.这公司从2014年2月份开始搞我,我去年的绩效是3.8/5.0,完全没有绩效问题.他们倒好,自从我查完我们公司某商业间谍之后,就给我穿小鞋,说我这个不好,那个拖延,这不是扯淡吗?公司在3月5日非法把我裁掉,而且直到现在还未支付我2月份工资,行吧,那我就不再沉默了,当我吃素的是吧!我现在把这件事情公之于众,望

线段树第二弹(区间更新)

上篇文章,我们介绍了线段树的基本概念和单点更新.区间查询,今天,我们来接着上次的线段树问题继续深入研究.在解决线段树问题的过程中,我们会遇到要求修改区间中某一元素值的问题,当然也可能会遇到要求修改一段子区间所有值的问题--即区间更新问题.回忆一下上篇文章单点更新的方法是,由叶节点逐级向上进行更新,此时更新一个节点值的时间复杂度为o(log n),(点击链接了解详情:线段树+RMQ问题第二弹),那么以这样的处理效率来进行区间更新结果会怎样?现在假设待更新区间数据的规模为 n ,那么就需要进行 n

黑马程序员:赶紧下载iOS10开发教程第二弹

虽然6月13日WWDC2016的发布会结束了,但是本届大会的开发者session环节还在持续进行着.黑马程序员本着对技术的狂热,对学生负责的态度,仍然坚持每天对课程进行深入的研发.本文主要是黑马程序员对iOS 10 中SDK所更新的主要内容进行总结.根据黑马程序员惯例,在文章的最后,有相关相关教学视频及Demo会有分享链接,供各位下载! 1.Grand Center Dispatch GCD 在本次一更新主要有以下内容: ?创建私有队列 ?安排异步执行的工作项目(items) ?GCD能自动将工

日均百万PV架构第二弹(缓存时代来临)

上一弹中我们规划并搭建了基本的架构组成,当然此架构存在诸多问题,我们在接下来的章节中将不断 完善其功能特性,使之成为实至名归的百万PV架构站点   首先来对上一弹架构做基本的ab 并发100, 总量2000的测试,让我们对站点性能有所熟知,之后在之前的功能上我们添加多道 缓存对性能进行提升. (ps: 测试机器均为虚拟机环境 , 大约性能比主流服务器低 2.5 - 3.5 倍 , 测试参 数可做此对比评估) 按照规划,我们在salve3.king.com中添加两实例的varnish,在slave

AndroidStudio使用教程(第二弹)

AndroidStudio使用教程(第二弹) 迁移Eclipse工程到Android Studio 官方文档中说Android Studio可以兼容Eclipse的现有工程,但需要做一些操作: Eclipse进行项目构建 首先升级ADT到最新版本, 好像是22之后,选择需要从Eclipse导出的工程,右键选择Export并选择Android下的Generate Gradle Build Files, 运行完成之后你会发现在项目目录中多了一个build.gradle, 这就是Android Stu

JVM第二弹

JVM第二弹 GC分代收集算法VS分区收集算法 分代收集算法 当前主流的VM垃圾收集都采用"分代收集"算法,这种算法会根据对象存活周期的不同将内存划分为几块,如JVM中的新生代.老年代.永久代,这样就可以根据个年代特点分别采用最适当的GC算法. 新生代·复制算法 每次垃圾收集都能发现大批对象已死,只有少量存活.因此选用复制算法,只需要付出少量存活对象的复制成本就可以完成收集. 老年代·标记整理算法 因为对象存活率高.没有额外空间对它进行分配担保,就必须采用"标记-清理&quo

深究angularJS系列 - 第二弹

深究angularJS系列 - 第二弹,在初步了解了Angular的基础上,进一步的针对Angular的控制器和作用域问题深入探究O(∩_∩)O~~ Angular控制器 控制器(Controller)的理解 控制器是对view的抽象,用来接收view的事件,响应view的请求: 控制器包含view的静态属性和动态的方法: 控制器与view是一对一的关系. 控制器(Controller)的结构 1 .controller("控制器的名字",function($scoppe){ 2 ..

MongoDB第二弹——基本操作

1 查看各个项目的Project ID编号 mysql -uroot -h10.10.2xx.xx show databases; use bugfree2; desc bf_TestProject; select ProjectID,ProjectName from bf_TestProject;(查询结果如下) 2 在/var/www/html/bugfree/BugFile路径下创建文件夹 mkdir Project2  Project3  Project4  Project5  Proj