450A - Jzzhu and Children 找规律也能够模拟

挺水的一道题。规律性非常强,在数组中找出最大的数max,用max/m计算出倍数t,然后再把数组中的书都减去t*m,之后就把数组从后遍历找出第一个大于零的即可了

#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
 //   freopen("in.txt","r",stdin);
    int a[105],n,m;
    while(~scanf("%d%d",&n,&m)){
        int max=0;
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            if(a[i]>max) max=a[i];
        }
        int t=max/m;
        if(max%m==0) t--;
        for(int i=0;i<n;i++){
            a[i]-=t*m;
        }
        int ans=-1;
        for(int i=n-1;i>=0;i--){
            if(a[i]>0){
                ans=i;
                break;
            }
        }
        if(t==0)
            cout<<n<<endl;
        else
            cout<<ans+1<<endl;
    }
}

posted @ 2016-01-13 12:41  zfyouxi  阅读(159)  评论(0编辑  收藏  举报