Ultraviolet A 10334 Ray Through Glasses

Source: Internet
Author: User

UVA_10334

This question can be guessed as a series of fibonacci columns.

If you want to prove it, let's take a look at how the light with the number of refraction n is made up, in fact, they are formed by drawing a Ray at the intersection of the final shot light with the number of refraction N-1 and the three crosslines in reverse direction.

Therefore, we can know that the number of final points between the emitted light and the horizontal line in all optical paths with the refraction number N-1 is the total number of optical paths with the refraction number n.

The intersection point can be divided into two types by the nature of the intersection point. We may use x to represent the intersection points formed by the light and the middle horizontal line, and y to represent the intersection points formed by the rays and the horizontal lines on both sides. It is not difficult to find that a class y intersection can be formed when the reverse light is injected at each class x intersection, A Class x intersection and a class y intersection can be formed when a reverse Ray is drawn at each class y intersection. When the number of refraction times is n, it is not difficult to write a recursive formula for the number of class x intersections and the number of class y intersections, x (n) = y (n-1), y (n) = x (n-1) + y (n-1), we add the two formulas to obtain x (n) + y (n) = x (n-1) + y (n-1) + y (n-1) = x (n-1) + y (n-1) + x (n-2) + y (n-2), so f (n) = x (n) + y (n), we can get f (n) = f (n-1) + f (n-2 ).

We have also explained the relationship between the number of X-ray points and the number of X-ray points. Since the number of X-ray points is a Fibonacci number, the number of Optical Paths is a Fibonacci number.

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger[] f = new BigInteger[1010];
f[0] = new BigInteger("1");
f[1] = new BigInteger("2");
for(int i = 2; i <= 1000; i ++)
f[i] = f[i - 1].add(f[i - 2]);
while(cin.hasNext())
{
int N = cin.nextInt();
System.out.println(f[N]);
}
}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.