国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

gym101138F(數學,暴力)

2019-11-11 01:28:34
字體:
來源:轉載
供稿:網友

題目鏈接F. GukiZ Heighttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

GukiZ loves hiking in the mountains. He starts his hike at the height 0 and he has some goal to reach, initially equal to h.

The mountains are described by a sequence of integers A0,?A1,?...,?An?-?1. In the first day GukiZ will change his height by A0, in the second day by A1, and so on. Mountains are a regular structure so the pattern repeats after the first n days. In general, in the i-th day GukiZ will change his height by A(i?-?1)%n.

Additionally, GukiZ will become more and more tired and in the i-th day his goal will decrease by i. For example, after first three days his goal will be equal to h?-?1?-?2?-?3?=?h?-?6.

Note that A may contain negative elements, what rePResents going down from some hill. Moreover, GukiZ's height may become negative, and so does his goal!

You can assume that both GukiZ's height and goal change at the same moment (immediately and simultaneously) in the middle of a day.

Once GukiZ is at the height not less than his goal, he ends his hike. Could you calculate the number of days in his hike?

Input

The first line of the input contains two integers n and h (1?≤?n?≤?105, 1?≤?h?≤?109) — the length of the array A and the initial goal, respectively. 

The second line contains n integers A0,?A1,?...,?An?-?1 (?-?109?≤?Ai?≤?109).

Output

In a single line print the number of days in the GukiZ's hike.

It can be proved that for any valid input the answer exists.

Examplesinput
3 457 -4 5output
7input
1 10output
1Note

GukiZ starts at height 0 with goal 45. We can describe his hike as follows:

After the first day he is at height 7 and his goal is 44. Height 3, goal 42. Height 8, goal 39. Height 15, goal 35. Height 11, goal 30. Height 16, goal 24. Height 23, goal 17. 

After the 7-th day Gukiz's height is not less than his goal so he ends his hike.

題意:

一個登山運動員,n座山,目標高度為h,然后給出n個數,運動員當前高度為前面所有山的高度和(注意山是重復的,第n座山后面是第一座山)。

同時,在第i天他的目標高度會見小i

當當前高度大于等于目標高度時,停止登山

求第幾天結束。

題解:

先判斷會不會在第一輪某一天就結束

如果沒有,那么假設進行x輪后結束,枚舉結束是在第x+i(1<=i<=n)天,然后對每個i算出最小的x,列一個不等式即可。

注意精度。

#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<queue>#include<stack>#include<cmath>using namespace std;#define rep(i,a,n) for (int i=a;i<n;i++)#define per(i,a,n) for (int i=n-1;i>=a;i--)#define pb push_back#define fi first#define se secondtypedef vector<int> VI;typedef long long ll;typedef pair<int,int> PII;const ll inf=0x3ffffffffffff;const ll mod=1000000007;const int maxn=1e5+10;ll a[maxn];ll sum=0;typedef long double db;int main(){    int n;    ll h;    scanf("%d%I64d",&n,&h);    rep(i,1,n+1) scanf("%I64d",&a[i]),sum+=a[i];    ll ans=inf;    ll h1=0;    rep(i,1,n+1)    {        h1+=a[i];        if(h1>=h-i*(i+1)/2)        {            printf("%d/n",i);            return 0;        }        db b=((db)i/n+1.0/2/n+(db)sum/n/n);        db c=((db)i*(i+1)/2-h+h1)/n/n;        db t=sqrtl(b*b-2*c);        t=t-b;        ans=min(ans,(ll)(i+ceill(t)*n));    }    printf("%I64d/n",ans);    return 0;}


上一篇:數組

下一篇:第二十四課 C API概述

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 尚义县| 吉林省| 清水河县| 紫阳县| 绍兴县| 太湖县| 五台县| 康定县| 金堂县| 宜君县| 华亭县| 会宁县| 秭归县| 日喀则市| 嘉定区| 仙游县| 河间市| 堆龙德庆县| 绥棱县| 萨迦县| 辉南县| 华容县| 民丰县| 抚松县| 榆社县| 北宁市| 长汀县| 商河县| 封开县| 田林县| 济宁市| 宜丰县| 浮山县| 基隆市| 新津县| 墨脱县| 渝中区| 汉中市| 宁远县| 桓台县| 石门县|