UVA 10623 Thinking Backward 欧拉公式

Problem A
Thinking Backward
Input: 
Standard Input

Output: Standard Output

Time Limit: 2 Seconds

 

Plane division by a common shape is a very well known topic of computer science.  The pictures below shows some such diagrams. In figure 1we find that four circles divide a plane in maximum 14 zones, four ellipses divide a plane in maximum 26 zones and three triangles divide a plane in maximum 20 zones. It is a common practice to find out the maximum number of regions when m  shapes of same type intersects. For example the general formula for circles is m2-m+2. When the situation is hybrid (More than one type of shapes intersect) the maximum possible number of regions is also not very difficult to find out.     

In figure 2 we can see that eight regions are created when one ellipse and one triangle intersect. In this problem you will have to think in the reverse direction. You will be given the maximum number of regions created and you will have to find how many ellipses, circles and triangles were involved.

 

Input 

The input file contains less than 300 lines of inputs. Each line contains a 32-bit unsigned integer N, which is the maximum number of regions, created by m ellipses, n circles and p triangles. Input is terminated by a line, which contains a –1. This line should not be processed. All input numbers other than the –1 in the last line are positive numbers.

 

Output 

For each line of input you have to produce two or more lines of output. The description of output for each line is given below:

 

The first line is the serial number of output. Each of the next lines contains three integers. These three integers are possible values of m ,n and pfor which maximum N regions is created. When there is more than one solution then the solutions should be sorted in ascending of m and then by ascending order of n. If there is no valid solution output a line “Impossible.” instead. Look at the output for sample input for details. Please note that for a valid solution 0<=m<1000<=n<20000 and 0<=p<100.

 

Sample Input                           Output for Sample Input

20
10
-1

Case 1:

0 0 3

0 1 2

1 0 2

1 3 0

Case 2:

Impossible.

 


Problemsetter: Shahriar Manzoor, Member of Elite Problemsetters' Panel
Special Thanks to Derek Kisman (Alternate solution and eliminating confusions) 



代码没保存下来,这个题可以用平面图的欧拉公式来推,连通的平面图满足一个这样的公式 V - E + F = 2 其中V是定点数,E是边数,F是面数。  根据这个我们能得出F的递推式。假设我们先放好椭圆,然后放一个三角形的时候,每个椭圆跟三角形有6个交点,算一下可以得出面数增加了椭圆数*6, 同样的道理,放完三角形,再放圆,圆跟椭圆4个交点,跟三角形6个交点,也是类似的递推关系,根据这个递推关系我们能够直接得出一个三元二次函数,设为f(x,y,z) x是椭圆的数目,y是三角形数目,z是圆的数目,我们可以枚举x,y的值,然后f(x,y,z)其实就是一个一元二次方程,直接解就行了。 这里枚举由于椭圆和三角形数目在100以内,所以枚举这两个会比较好。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值