【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 + 和 ~的区别
<style type="text/css"> h1 + p { margin-top:50px; color:red; } </style> <p& ...
- vue开发 - 根据vue-router的meta动态设置html里标签的内容
路由文件 :router/index.js import Vue from 'vue'import Router from 'vue-router'import index '@/view/index ...
- java配置日志总结
log4j 搭建日志环境 简单非maven项目,只需要引入log4j.jar,在类路径下添加log4j.properties即可 简单maven项目,只需要在pom.xml引入dependency,在 ...
- 【makefile】symbol <函数> : can't resolve symbol 问题分析
调试程序的时候,在linux编译器上可以编译通过,但是编译生成的firmware烧录到板子上的后出现以下异常: can't resolve symbol,无法解析元素符号. review一下code, ...
- c++基础_矩阵乘法
#include <iostream> using namespace std; int main(){ int a,b; cin>>a>>b; long c[a] ...
- (贪心) Vacations 求休息的最少天数
Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasy ...
- 【20】AngularJS 参考手册
AngularJS 参考手册 AngularJS 指令 用到的 AngularJS 指令 : 指令 描述 解析 ng-app 定义应用程序的根元素. 指令 ng-bind 绑定 HTML 元素到应用程 ...
- markman & psd
markman & psd MarkMan 设计稿标 & 测量神器 http://www.getmarkman.com/ https://www.jianshu.com/p/83af3 ...
- Linux下汇编语言学习笔记53 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- SharedPreferences保存用户偏好参数
package com.example.administrator.myapplication; import android.content.Context; import android.cont ...