题意

  给你一串数,a1...an,从左到右每次让一个数减小c,如果这个数小于c,那就减为0。第n个数减小后,又从第一个开始从左到右。如果这次某个数减小到0,那就改变方向,如果遇到已经是0的,就跳过。且总共最多减少n+5次,求最后变为0的数是第几个。

分析

Input

1

8 80
200 100 100 100 100 80 160 200

Output

3

样例分析:

最多可以减少8+5=13次,于是最后减为0的就是第三个数了:

    200 100 100 100 100 80 160 200 减少次数
第一轮 120 20 20 20 20 0 160 200  6
改变方向120 20 20 20 0 160 200  7
改变方向120 20 20 20 0 0 80 120  9
第二轮 40 0 20 20 0 0 80 120  11
改变方向 0 20 20 0 0 80 120  12
改变方向 0 0 20 0 0 80 120  13

这题理解了题意,模拟就好啦。

代码

#include<cstdio>

int t;
int n,c;
int s[];
int bite,left;
int now,next;
int ans; int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&c); for(int i=; i<n; i++)
scanf("%d",&s[i]); now=;
next=;
bite=n+;
left=n; while(left&&bite)
{
if(s[now]>)
{
s[now]-=c;
if(s[now]<=)
{
next=-next;
left--;
}
bite--;
ans=now;
}
now=(now+next+n)%n;
}
printf("%d\n",ans+);
}
return ;
}

【ZOJ 3897】Candy canes//Fiddlesticks的更多相关文章

  1. 【ZOJ 4070】Function and Function

    [链接] 我是链接,点我呀:) [题意] [题解] 递归一会. 会发现最后肯定是0,1一直循环. 开始循环之后就直接返回结果就好. [代码] #include <bits/stdc++.h> ...

  2. 【ZOJ 4060】Flippy Sequence

    [链接] 我是链接,点我呀:) [题意] [题解] 按照两个区间的排列方式 我们可以分成以下几种情况 会发现这两个区间的作用 最多只能把两段连续不同的区间变为相同. 那么写个for处理出连续不相同的一 ...

  3. 【ZOJ 4067】Books

    [链接] 我是链接,点我呀:) [题意] [题解] 统计a中0的个数cnt0 然后m减去cnt0 因为这cnt0个0是一定会取到的. 如果m==0了 那么直接找到数组中的最小值mi 输出mi-1就好 ...

  4. 【ZOJ 4062】Plants vs. Zombies

    [链接] 我是链接,点我呀:) [题意] [题解] 二分最后的最大抵御值mid. 然后对于每个蘑菇. 都能算出来它要浇水几次mid/ai 然后如果第i个蘑菇没浇水达到要求次数. 就在i和i+1之间来回 ...

  5. 【Zoj 4061】Magic Multiplication

    [链接] 我是链接,点我呀:) [题意] [题解] /* for a[1] from 1~9 1*1=1 2*1=2 3*1=3 1*2=2 2*2=4 3*2=6 1*3=3 2*3=6 3*3=9 ...

  6. 【LEETCODE OJ】Candy

    Problem link: http://oj.leetcode.com/problems/candy/ Suppose we are given an array R[1..N] that are ...

  7. 【LeetCode练习题】Candy

    分糖果 There are N children standing in a line. Each child is assigned a rating value. You are giving c ...

  8. 【ZOJ 3200】Police and Thief

    ZOJ 3200 首先我写了个高斯消元,但是消出来了一些奇怪的东西,我就放弃了... 然后只好考虑dp:\(dp[i][j][k]\)表示走到了第i步,到了\((j,k)\)这个节点的概率. 那么答案 ...

  9. 【ZOJ 3463】Piano

    ZOJ 3463 题意:有一个钢琴,一个人把左手放在L位置上,右手放在R位置上,要弹某\(n\)个键,每个手最多能够得着9个位置,并且两只手不能交叉.把手移动的代价是大拇指移动的距离的平方根.问弹完这 ...

随机推荐

  1. js立即执行函数: (function ( ){...})( ) 与 (function ( ){...}( )) 有区别?

    没有区别. 你需要明白 IIFE 的原理,我简单说一下: function foo() {...} // 这是定义,Declaration:定义只是让解释器知道其存在,但是不会运行. foo(); / ...

  2. Linq中查询List组合相同值数量大于1

     List< select g.Key).ToList();

  3. 在centos下部署docker内网私服

    Docker内网私服:docker-registry with nginx & ssl on centos docker-registry既然也是软件应用,自然最简单的方法就是使用官方提供的已 ...

  4. Eclipse调试按钮消失问题

    Window-->Reset Perspective 把Eclipse重置一下,然后 点击红色框圈的向下的箭头,在弹出的菜单里边,点击 show debug toolbar 这个菜单项目,然后奇 ...

  5. AD域的安装

    AD域的安装 初始化设置,改计算机名字dcserver,改静态ip,改dns指向自己. dcpromo,执行后自动装了dns.   装完后检查 1,本地用户没了 2,dns指向自己 3,dns记录是否 ...

  6. U3D assetbundle打包

    using UnityEngine; using System.Collections; using UnityEditor; //此脚本不一定要放于editor目录下,经测试,放于其它地方也可以 p ...

  7. ASP.NET Web API身份验证和授权

    英语原文地址:http://www.asp.net/web-api/overview/security/authentication-and-authorization-in-aspnet-web-a ...

  8. [CareerCup] 3.3 Set of Stacks 多个栈

    3.3 Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in ...

  9. LeetCode:Climbing Stairs(编程之美2.9-斐波那契数列)

    题目链接 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either c ...

  10. error C3872: "0xa0": 此字符不允许在标识符中使用

    整理:这是因为直接复制代码的问题.0xa0是十六进制数,换成十进制就是160,表示汉字的开始. 解决办法:在报错的代码行检查两边的空格,用英文输入法的空格替换掉. 万恶的网络,万恶的word,这些无厘 ...