Problem Description
Problem Analysis
Actually, the simplest approach is a simulation loop
The idea is also very simple
And it does not time out for this problem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| #include<stdio.h>
int main() {
int T;
scanf("%d",&T);
while(T--) {
int H;
scanf("%d",&H);
if(H<=5)
printf("1\n");
else {
int cnt=0;
int h=5;
while(h<H) {
h-=5;
cnt++;
h+=10;
}
printf("%d\n",cnt);
}
}
return 0;
}
|
However, you can also find the pattern
which instantly reduces the time
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| #include<stdio.h>
int main() {
int T;
scanf("%d",&T);
while(T--) {
int H;
scanf("%d",&H);
if(H<=10)
printf("1\n");
else
printf("%d\n",(H-1)/5);
}
return 0;
}
|
This problem did not provide a standard solution
-.- But I think mine is good enough to serve as the standard solution
Well…
Maybe writing it this way is more concise
1
2
3
4
5
6
7
8
9
10
11
| #include<stdio.h>
int main() {
int T;
scanf("%d",&T);
while(T--) {
int H;
scanf("%d",&H);
printf("%d\n",H<=10?1:(H-1)/5);
}
return 0;
}
|
Hahaha
The ? expression is still very convenient
Problem address:Hardworking Little Snail