[LightOJ] [1008] Fibsieve's Fantabulous Birthday

Problem Description

Loading...

Problem Analysis

The first time I encountered such a high-end foreign OJ
I immediately felt it was really badass

For this problem
By observation, you can find that the row and column of a number have some relationship with the square root of the number
So after careful analysis

You can separate odd and even cases and some other factors such as the magnitude of the number
to determine the row and column where the number is located

The AC code is as follows

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<stdio.h>
#include<math.h>
int main() {
	int T;
	long long S,x,y,m;
	int i;
	scanf("%d",&T);
	for(i=1; i<=T; i++) {
		scanf("%lld",&S);
		m=ceil(sqrt((double)S));
		if(sqrt((double)S)-m>0)
			m++;
		if(m&1) {
			if(m*m-S<m) {
				y=m;
				x=m*m-S+1;
			} else {
				x=m;
				y=S-(m-1)*(m-1);
			}
		} else {
			if(m*m-S<m) {
				x=m;
				y=m*m-S+1;
			} else {
				y=m;
				x=S-(m-1)*(m-1);
			}
		}
		printf("Case %d: %lld %lld\n",i,x,y);
	}
	return 0;
}

Problem link: LightOJ 1008 Fibsieve`s Fantabulous Birthday

Excellent explanation: Finding the pattern LightOJ 1008

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