[Zhengqing] [1798] Daimler's Plea for Help

Problem Description

Loading...

Problem Analysis

A problem about nitpicking data precision
My senior said he hates this kind of problem the most…
I got WA many times back then
At one point I doubted whether this problem was even doable
Then my direction of thinking was wrong
Then @A_ice gave me her AC code
The idea is just adding a small decimal as the problem hint says
(the decimal I added at the time was not small enough)
As follows:

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include<stdio.h>
#include<math.h>
int main() {
	int T;
	long long m,n;
	scanf("%d",&T);
	while(T--) {
		scanf("%lld",&n);
		m=(long long)(pow(n,1.0/3)+0.000000001);
		printf("%lld\n",m);
	}
	return 0;
}

My senior gave me his verification approach
that is, manually multiply it three times to check
The code is as follows:

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
#include<math.h>
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		long long n,sum;
		scanf("%lld",&n);
		sum=pow(n*1.0,1.0/3);
		while(sum*sum*sum<=n)
		{
			sum++;
		}
		printf("%lld\n",sum-1);
	}
	return 0;
}

Problem link: ZZULI 1798: Daimler’s Request for Help

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...