A. Milking cows
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).

Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.

Input

The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.

Output

Print a single integer, the minimum amount of lost milk.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the%I64d specifier.

Sample test(s)
input
4
0 0 1 0
output
1
input
5
1 0 1 0 1
output
3
 思路:先将脸朝左的牛按顺序从右到左挤,再把脸朝右的牛按顺序从左向右挤,这样才能让损失量最少;
AC Code:

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define N 200005
long long int ans, cow[N], lose[N];
int main(int argc, char const *argv[])
{
int n;
/* freopen("in.c", "r", stdin); */
while(cin >> n)
{
ans = ;
memset(lose, , sizeof(lose));
for(int i = ;i <= n;i ++)
{
cin >> cow[i];
lose[i] = lose[i-] + cow[i];
if(cow[i] == )
ans += lose[i];
}
cout << ans << endl;
}
return ;
}

codeforce ---A. Milking cows的更多相关文章

  1. Milking Cows

    Milking Cows Three farmers rise at 5 am each morning and head for the barn to milk three cows. The f ...

  2. 洛谷P1204 [USACO1.2]挤牛奶Milking Cows

    P1204 [USACO1.2]挤牛奶Milking Cows 474通过 1.4K提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 请各位帮忙看下程序 错误 ...

  3. 【题解】Luogu P1204 [USACO1.2]挤牛奶Milking Cows

    原题传送门:P1204 [USACO1.2]挤牛奶Milking Cows 实际是道很弱智的题目qaq 但窝还是觉得用珂朵莉树写会++rp(窝都初二了,还要考pj) 前置芝士:珂朵莉树 窝博客里对珂朵 ...

  4. Milking Cows 挤牛奶

    1.2.1 Milking Cows 挤牛奶 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 554  Solved: 108[Submit][Status ...

  5. 【洛谷P1204】【USACO1.2】挤牛奶Milking Cows

    P1204 [USACO1.2]挤牛奶Milking Cows 题目描述 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒.第二个 ...

  6. Milking Cows 挤牛奶 USACO 排序 模拟

    1005: 1.2.1 Milking Cows 挤牛奶 时间限制: 1 Sec  内存限制: 128 MB提交: 15  解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1 ...

  7. 【USACO】Milking Cows

    Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer b ...

  8. USACO Section 1.2 Milking Cows 解题报告

    题目 题目描述 有3个农夫每天早上五点钟便起床去挤牛奶,现在第一个农夫挤牛奶的时刻为300(五点钟之后的第300个分钟开始),1000的时候结束.第二个农夫从700开始,1200结束.最后一个农夫从1 ...

  9. 洛谷 P1204 [USACO1.2]挤牛奶Milking Cows Label:模拟Ex 74分待查

    题目描述 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒.第二个农民在700秒开始,在 1200秒结束.第三个农民在1500秒开 ...

随机推荐

  1. KinSlideshow参数设置说明

    [引用来自:http://blog.sina.com.cn/s/blog_4f4f4a5901014zn1.html] Jquery.KinSlideshow参数设置说明: 附:所有参数列表   in ...

  2. (转)xml序列化

    在 .NET Framework 中提供两种串行化方法,一种是二进制法,另一种是xml串行化. 序列化是将对象状态转换为可保持或传输的格式的过程,xml序列化是将对象的公共字段和属性序列化为xml流. ...

  3. 学习java随笔第九篇:java异常处理

    在java中的异常处理和c#中的异常处理是一样的都是用try-catch语句. 基本语法如下 try { //此处是可能出现异常的代码 } catch(Exception e) { //此处是如果发生 ...

  4. andriod 中设置sdk升级代理服务器

    Android SDK 在线更新镜像服务器资源: 大连东软信息学院镜像服务器地址: http://mirrors.neusoft.edu.cn 端口:80 北京化工大学镜像服务器地址: IPv4: h ...

  5. MySQL 连接数据库

    一.MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格),缺点:密码显示在显示器上,容易泄露. C:\>mysql -h localho ...

  6. FXBlurView用法

    FXBlurView是UIView的子类,它实现毛玻璃效果的原理其实就是覆盖上一层FXBlurView的实例对象. - (void)viewDidLoad { [super viewDidLoad]; ...

  7. PHP 学习笔记 (三)

    stream_context_create()函数的用法: $url = "http://www.someweb.com" $context = stream_context_cr ...

  8. LINUX命令行操作

    Linux 命令行快捷键 7条回复 涉及在linux命令行下进行快速移动光标.命令编辑.编辑后执行历史命令.Bang(!)命令.控制命令等.让basher更有效率. 说明 Ctrl – k: 先按住 ...

  9. javascript判断设备类型-手机(mobile)、安卓(android)、电脑(pc)、其他(ipad/iPod/Windows)等

    使用device.js检测设备并实现不同设备展示不同网页 html代码: <!doctype html> <html> <head> <meta charse ...

  10. 代码世界中的Lambda

    “ λ ”像一个双手插兜儿,独自行走的人,有“失意.无奈.孤独”的感觉.λ 读作Lambda,是物理上的波长符号,放射学的衰变常数,线性代数中的特征值……在程序和代码的世界里,它代表了函数表达式,系统 ...