Hdoj 1418 Sorry (Euler formula)

Source: Internet
Author: User

Problem Description
I am very sorry, originally excitedly engaged in a practice game, because I am not prepared enough, there are a lot of data errors, now here for a simple topic:

A few days ago on the internet to find ACM data, see a high School Olympiad question, is disjoint curve segment division plane problem, I have sent to the forum, and LXJ has got a conclusion, here is not

More than that, here's a similar and simpler question:

If there are n points on the plane, and each point has at least 2 curved segments connected to it, that is, each curve is closed, and we stipulate that:
1) All curved segments do not intersect;
2) But there can be more than one curve segment between any two points.

If we know that these line segments divide the plane into m parts, can you tell how many curved segments there are?

Input
The input data contains N and m,n=0,m=0 to indicate the end of the input, not to be processed.
All input data is within a 32-bit integer range.

Output
The output corresponds to the number of segments.

Sample Input
3 2
0 0

Sample Output
3

Application of Euler's formula:
Euler formula:
A relationship between the number of vertices of a simple polyhedron V, the number of polygons F and the number of edges E
v+f-e=2
(This topic: Vertex + polygon number -2= number of edges)
You can deduce it yourself!
Imagine that n points are enclosed in a closed graph, which is divided into 2 polygons.
This time the line segment is the N bar.
If you need to add a polygon, the segment needs to be added one more.

So, input n points, divided into M-plane, it can be deduced that the segment is n-2+m.

Note: n+m is super int range!

import java.util.scanner; Public  class  main{public  static  void  main  (string[] args) {Scanner sc = new  Scanner (system.        In ); while  (Sc.hasnext ())            {long  n = sc.nextlong ();            long  m = Sc.nextlong (); if  (N==0  &&m==0 )            {return ; } System.        out . println (N+m-2 ); }    }}

Hdoj 1418 Sorry (Euler formula)

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.