您的位置:首页 > 其它

450A - Jzzhu and Children 找规律也可以模拟

2014-07-21 19:41 344 查看
挺水的一道题,规律性很强,在数组中找出最大的数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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: