【bzoj4412】[Usaco2016 Feb]Circular Barn
先看成一条链
for一遍找位置
在for一遍算答案
- #include<algorithm>
- #include<iostream>
- #include<cstring>
- #include<string>
- #include<cstdio>
- #include<cmath>
- using namespace std;
- typedef long long LL;
- #define N 100010
- int n;
- int cnt=;
- int a[N<<],s[N<<];
- int main()
- {
- freopen("a.in","r",stdin);freopen("a.out","w",stdout);
- scanf("%d",&n);
- for (int i=;i<=n;i++)
- scanf("%d",&a[i]),a[n+i]=a[i];
- for (int i=;i<=n*;i++)
- {
- if (i==cnt+n)
- break;
- s[i]=s[i-]+a[i]-;
- while (s[i]<s[cnt-])
- cnt++;
- }
- LL ans=;
- int l=cnt+n-,r=cnt+n-;
- while (r>=cnt)
- {
- while (!a[l])
- l--;
- ans+=(LL)(r-l)*(r-l);
- a[l]--;
- r--;
- }
- printf("%lld\n",ans);
- return ;
- }
【bzoj4412】[Usaco2016 Feb]Circular Barn的更多相关文章
- bzoj 4412: [Usaco2016 Feb]Circular Barn
4412: [Usaco2016 Feb]Circular Barn Description 有一个N个点的环,相邻两个点距离是1.点顺时针标号为1..N.每一个点有ci头牛,保证∑ci=N.每头牛都 ...
- BZOJ4409 [Usaco2016 Feb]Circular barn 动态规划 斜率优化
原文链接http://www.cnblogs.com/zhouzhendong/p/8724739.html 题目传送门 - BZOJ4409 题意 有一个N个点的环,相邻两个点距离是1.点顺时针标号 ...
- 【BZOJ3940】【BZOJ3942】[Usaco2015 Feb]Censoring AC自动机/KMP/hash+栈
[BZOJ3942][Usaco2015 Feb]Censoring Description Farmer John has purchased a subscription to Good Hoov ...
- 【BZOJ3943】[Usaco2015 Feb]SuperBull 最小生成树
[BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...
- 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树
[BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...
- 【BZOJ3943】[Usaco2015 Feb]SuperBull 最大生成树
[BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...
- 树状数组【bzoj1782】: [Usaco2010 Feb]slowdown 慢慢游
[bzoj1782]: [Usaco2010 Feb]slowdown 慢慢游 Description 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1-N) ...
- 【BZOJ3940】[USACO2015 Feb] Censoring (AC自动机的小应用)
点此看题面 大致题意: 给你一个文本串和\(N\)个模式串,要你将每一个模式串从文本串中删去.(此题是[BZOJ3942][Usaco2015 Feb]Censoring的升级版) \(AC\)自动机 ...
- 带权并查集【bzoj3362】: [Usaco2004 Feb]Navigation Nightmare 导航噩梦
[bzoj]3362: [Usaco2004 Feb]Navigation Nightmare 导航噩梦 农夫约翰有N(2≤N≤40000)个农场,标号1到N,M(2≤M≤40000)条的不同的垂 ...
随机推荐
- CSS Paint API绘制透明格子背景实例页面
CSS代码: .box { width: 180px; height: 180px; background: paint(transparent-grid); } HTML代码: <div cl ...
- Python 文件修改-函数介绍
上节课复习:1.字符编码 1.1 如何解决乱码问题: 字符存取使用的编码标准不一致 1.2 文件头 在文件的首行写入文件头,用于控制Python解释器读取py文件内容时使用的编码 #coding:文件 ...
- Python之面向对象函数式编程
Python之面向对象函数式编程 函数式编程的根本就是用 def 去模拟数学式的编程逻辑. 类似与 y = 2*x + 1 ,当x = 3 时,函数的结果y就得7. def test(x): retu ...
- python 库文件版本收集及安装
版本收集:pip freeze > require.txt版本安装:pip install -r require.txt
- LeetCode(56)Merge Intervals
题目 Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6], ...
- 绑定IP 绑定设备
首先引别人的组播测试如下 1. 一个udp client可以同时往多个组播地址发送数据,多个udpclient可以同时往一个组播发数据. 2. 本地udp必须监听组播端口,否则收不到数据.3. 一个u ...
- angular2集成highchart
集成highchart的配置困扰了我很久,今天终于解决了: 1.修改tsconfig.app.json: "compilerOptions": { //... "type ...
- LaTex/Overleaf使用笔记
1. 添加网页引用 @misc{ r1, author = "Wikipedia", title = "Binary decision diagram --- { ...
- Codeforces Round #355 (Div. 2)-B. Vanya and Food Processor,纯考思路~~
B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input s ...
- bzoj——3555: [Ctsc2014]企鹅QQ
3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 2617 Solved: 921[Submit][Statu ...