[CodeForces] [617A] Elephant

Problem Description

Loading...

Problem Analysis

Each time, just greedily take the largest possible step.

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include<stdio.h>
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int cnt=0;
		for(int i=5;i>0;i--){
			if(n>=i){
				cnt+=n/i;
				n%=i;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Problem link: 【CodeForces】[617A]Elephant

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...