【bzoj4412】[Usaco2016 Feb]Circular Barn

先看成一条链

for一遍找位置

在for一遍算答案

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<string>
 5 #include<cstdio>
 6 #include<cmath>
 7 using namespace std;
 8 
 9 typedef long long LL;
10 
11 #define N 100010
12 
13 int n;
14 int cnt=1;
15 
16 int a[N<<2],s[N<<2];
17 
18 int main()
19 {
20     freopen("a.in","r",stdin);freopen("a.out","w",stdout);
21     scanf("%d",&n);
22     for (int i=1;i<=n;i++)
23         scanf("%d",&a[i]),a[n+i]=a[i];
24     for (int i=1;i<=n*2;i++)
25     {
26         if (i==cnt+n)
27             break;
28         s[i]=s[i-1]+a[i]-1;
29         while (s[i]<s[cnt-1])
30             cnt++;
31     }
32     LL ans=0;
33     int l=cnt+n-1,r=cnt+n-1;
34     while (r>=cnt)
35     {
36         while (!a[l]) 
37             l--;
38         ans+=(LL)(r-l)*(r-l);
39         a[l]--;
40         r--;
41     }
42     printf("%lld\n",ans);
43     return 0;
44 }

 

转载于:https://www.cnblogs.com/yangjiyuan/p/5324248.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值