codeforce ---A. Milking cows
1 second
256 megabytes
standard input
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.
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.
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.
4
0 0 1 0
1
5
1 0 1 0 1
3
#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的更多相关文章
- Milking Cows
Milking Cows Three farmers rise at 5 am each morning and head for the barn to milk three cows. The f ...
- 洛谷P1204 [USACO1.2]挤牛奶Milking Cows
P1204 [USACO1.2]挤牛奶Milking Cows 474通过 1.4K提交 题目提供者该用户不存在 标签USACO 难度普及- 提交 讨论 题解 最新讨论 请各位帮忙看下程序 错误 ...
- 【题解】Luogu P1204 [USACO1.2]挤牛奶Milking Cows
原题传送门:P1204 [USACO1.2]挤牛奶Milking Cows 实际是道很弱智的题目qaq 但窝还是觉得用珂朵莉树写会++rp(窝都初二了,还要考pj) 前置芝士:珂朵莉树 窝博客里对珂朵 ...
- Milking Cows 挤牛奶
1.2.1 Milking Cows 挤牛奶 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 554 Solved: 108[Submit][Status ...
- 【洛谷P1204】【USACO1.2】挤牛奶Milking Cows
P1204 [USACO1.2]挤牛奶Milking Cows 题目描述 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒.第二个 ...
- Milking Cows 挤牛奶 USACO 排序 模拟
1005: 1.2.1 Milking Cows 挤牛奶 时间限制: 1 Sec 内存限制: 128 MB提交: 15 解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1 ...
- 【USACO】Milking Cows
Three farmers rise at 5 am each morning and head for the barn to milk three cows. The first farmer b ...
- USACO Section 1.2 Milking Cows 解题报告
题目 题目描述 有3个农夫每天早上五点钟便起床去挤牛奶,现在第一个农夫挤牛奶的时刻为300(五点钟之后的第300个分钟开始),1000的时候结束.第二个农夫从700开始,1200结束.最后一个农夫从1 ...
- 洛谷 P1204 [USACO1.2]挤牛奶Milking Cows Label:模拟Ex 74分待查
题目描述 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒.第二个农民在700秒开始,在 1200秒结束.第三个农民在1500秒开 ...
随机推荐
- 关于 复制文本 然后Ctrl+V 操作的这个功能 貌似jq也没有封装。。。
/* * copy */ function copy(){ var maintext=$("#myhtml").val(); alert(maintext); copyToClip ...
- 今天把PHP复习了一下.
记录一下今天复习内容. $_GET[''] $_POST $_SESSION $_COOKIE 常用的 $var='a'; global 全局变量$GLOBALS[''] $$var (动态变量名的变 ...
- HierarchicalDataBoundControl 错误
出现以上错误原因是控件Datasources绑定出错,可能原因是没有区分树形结构的控件如Treeview的绑定与二维数据如datagridview绑定之间的区别.
- [XML] C#XMLProcess操作Xml文档的帮助类 (转载)
点击下载 XMLProcess.rar 主要功能如下所示 看下面代码吧 /// <summary> /// 类说明:XMLProcess /// 编 码 人:苏飞 /// 联系方式:361 ...
- jquery ajax跨域取数据
jsonp.js/html 主要是利用jquery ajax和jsonp的datatype 跨站点请求数据,记录~ 同源策略:同端口,同协议,同域:所以ajax不能支持跨域取得数据,解决方案一般是js ...
- jquery值ajaxForm
参考 http://www.360doc.com/content/13/1001/17/1542811_318406421.shtml
- HttpRequest 和HttpWebRequest的区别
[1]问题: asp.NET C# 中HttpRequest 和HttpWebRequest的区别 HttpRequest 与HttpWebRequest 有什么区别? 网上中文的帖子很多,但是答案 ...
- CSS一级导航-天蓝色(带阴影)
一款亮丽的导航,能给网站一个画龙点睛的作用.导航在指引用户搜寻内容时,还能改变用户浏览网站的心情,浏览网站也像一场旅行,有创意的导航栏让用户欣赏起来也会更加愉悦,增加对网站的兴趣. 本人不擅长美工制作 ...
- window.frameElement属性
比如有一个iframe的src是xxx.htm frameElement的作用就是在xxx.htm中获得这个引用它的iframe objet 这样你就可以在xxx.htm改变iframe的大小,或是边 ...
- 通过try、except和else的使用来使Python程序更加“强壮”
在执行的程序中,难免会碰到因为一些原因如输入输出导致致命性错误产生的情况(如因为输入的文件名错误而导致无法运行相关的代码.).此时你不希望程序直接挂掉,而是通过显示一些信息,使其平稳的结束.此时,就可 ...