【题目链接】

点击打开链接

【算法】

树状数组

【代码】

#include<bits/stdc++.h>

using namespace std;

int i,N,ans,l1,l2;
int c[],val[],id[]; template <typename T> void read(T &x) {
int f=; char c = getchar(); x=;
for (; !isdigit(c); c = getchar()) { if (c=='-') f=-; }
for (; isdigit(c); c = getchar()) x=x*+c-'';
x*=f;
} bool cmp(int a,int b) {
return val[a] > val[b];
} int lowbit(int x) {
return x & -x;
} int query(int x) {
int sum=;
while (x >= ) {
sum += c[x];
x -= lowbit(x);
}
return sum;
} void change(int x,int y) {
while (x <= N) {
c[x] += y;
x += lowbit(x);
}
} int main() { scanf("%d",&N);
for (i = ; i <= N; i++) {
scanf("%d",&val[i]);
id[i] = i;
}
sort(id+,id+N+,cmp); for (i = ; i <= N; i++) {
l1 = query(id[i]-);
l2 = i - l1 - ;
if (max(l1,l2) > min(l1,l2) * ) ans++;
change(id[i],);
} printf("%d\n",ans); return ; }

【USACO】 Balanced Photo的更多相关文章

  1. 【USACO】 Balanced Lineup

    [题目链接] 点击打开链接 [算法] 这是一道经典的最值查询(RMQ)问题. 我们首先想到线段树.但有没有更快的方法呢?对于这类问题,我们可以用ST表(稀疏表)算法求解. 稀疏表算法.其实也是一种动态 ...

  2. POJ 1986 Distance Queries / UESTC 256 Distance Queries / CJOJ 1129 【USACO】距离咨询(最近公共祖先)

    POJ 1986 Distance Queries / UESTC 256 Distance Queries / CJOJ 1129 [USACO]距离咨询(最近公共祖先) Description F ...

  3. 1642: 【USACO】Payback(还债)

    1642: [USACO]Payback(还债) 时间限制: 1 Sec 内存限制: 64 MB 提交: 190 解决: 95 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 &quo ...

  4. 1519: 【USACO】超级书架

    1519: [USACO]超级书架 时间限制: 1 Sec 内存限制: 64 MB 提交: 1735 解决: 891 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 Farmer Jo ...

  5. Java实现【USACO】1.1.2 贪婪的礼物送礼者 Greedy Gift Givers

    [USACO]1.1.2 贪婪的礼物送礼者 Greedy Gift Givers 题目描述 对于一群要互送礼物的朋友,你要确定每个人送出的礼物比收到的多多少(and vice versa for th ...

  6. 【CPLUSOJ】【USACO】【差分约束】排队(layout)

    [题目描述] Robin喜欢将他的奶牛们排成一队.假设他有N头奶牛,编号为1至N.这些奶牛按照编号大小排列,并且由于它们都很想早点吃饭,于是就很可能出现多头奶牛挤在同一位置的情况(也就是说,如果我们认 ...

  7. 【LeetCode】Balanced Binary Tree 解题报告

    [题目] Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bi ...

  8. 【USACO】Dining

    [题目链接] [JZXX]点击打开链接 [caioj]点击打开链接 [算法] 拆点+网络流 [代码] #include<bits/stdc++.h> using namespace std ...

  9. 【USACO】Optimal Milking

    题目链接 :        [POJ]点击打开链接        [caioj]点击打开链接 算法 : 1:跑一遍弗洛伊德,求出点与点之间的最短路径 2:二分答案,二分”最大值最小“ 3.1:建边,将 ...

随机推荐

  1. Netty和Akka有什么不同?

    摘要: Akka is a concurrency framework built around the notion of actors and composable futures, Akka w ...

  2. Java_AOP原理

    AOP : 面向切面编程 在程序设计中,我们需要满足高耦合低内聚,所以编程需满足六大原则,一个法则. AOP面向切面编程正是为了满足这些原则的一种编程思想. 一.装饰者模式: 当我们需要给对象增加功能 ...

  3. 1861 奶牛的数字游戏 2006年USACO

    codevs——1861 奶牛的数字游戏 2006年USACO  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze 题解       题目描述 Descript ...

  4. 心脏滴血漏洞复现(CVE-2014-0160)

    漏洞范围: OpenSSL 1.0.1版本 漏洞成因: Heartbleed漏洞是由于未能在memcpy()调用受害用户输入内容作为长度参数之前正确进 行边界检查.攻击者可以追踪OpenSSL所分配的 ...

  5. Centos常用命名

    1.关机 (系统的关机.重启以及登出 ) 的命令 shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3) shutdown -h hours: ...

  6. ios 处理内存警告

    iPhone下每个app可用的内存是被限制的,如果一个app使用的内存超过20M,则系统会向该app发送Memory Warning消息.收到此消息后,app必须正确处理,否则可能出错或者出现内存泄露 ...

  7. jmeter.properties控制聚合报告的用户响应时间设置和smmary results

    jmeter.properties的配置Summariser控制输出Summary Results,可以显式rt和tps等信息 Aggregate Report配置可以控制聚合报告的内容,控制90%用 ...

  8. C语言qsort

    C/C++中有一个快速排序的标准库函数 qsort ,在stdlib.h 中声明,其原型为: void qsort(void *base, int nelem, unsigned int width, ...

  9. hadoop优质链接

    http://wiki.apache.org/hadoop/FAQ

  10. android 学习笔记四:控件

    1.android:gravity 指定控件的基本位置,比如居中.居右等位置 Top:顶部 bottom:底部 left:居左 right:居右 center_vertical:垂直居中 center ...