zoukankan      html  css  js  c++  java
  • [UVA] 10167

     Problem G. Birthday Cake 

    Background

    Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them.Now we put the cake onto a Descartes coordinate. Its center is at (0,0), and the cake's length of radius is 100.

    There are 2N (N is a integer, 1<=N<=50) cherries on the cake. Mother wants to cut the cake into two halves with a knife (of course a beeline). The twins would like to be treated fairly, that means, the shape of the two halves must be the same (that means the beeline must go through the center of the cake) , and each half must have N cherrie(s). Can you help her?

    Note: the coordinate of a cherry (x , y) are two integers. You must give the line as form two integers A,B(stands for Ax+By=0), each number in the range [-500,500]. Cherries are not allowed lying on the beeline. For each dataset there is at least one solution.

    Input

    The input file contains several scenarios. Each of them consists of 2 parts: The first part consists of a line with a number N, the second part consists of 2N lines, each line has two number, meaning (x,y) .There is only one space between two border numbers. The input file is ended with N=0.

    Output

    For each scenario, print a line containing two numbers A and B. There should be a space between them. If there are many solutions, you can only print one of them.

    Sample Input

    2
    -20 20
    -30 20
    -10 -50
    10 -5
    0

    Sample Output

    0 1

    题解:暴力枚举+线性规划。A、B都是整数且范围为[-500,500],1<=N<=50,所以暴力枚举即可。统计一下直线一侧点的数目是否为N。注意有点在直线上的情况是不合法的。

    代码:
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdbool.h>
     4 
     5 int i,j,n,m,sum,
     6     a[110],b[110];
     7 
     8 int 
     9 init()
    10 {
    11     int i;
    12     m=2*n;
    13     for(i=1;i<=m;i++)
    14     scanf("%d%d",&a[i],&b[i]);
    15     
    16     return 0;
    17 }
    18 
    19 int 
    20 main()
    21 {
    22     int i,j,k,f;
    23     while(true)
    24     {
    25         scanf("%d",&n);
    26         if(n==0) break;
    27         init();
    28         f=0;
    29         for(i=-500;i<=500;i++)
    30         {
    31             for(j=-500;j<=500;j++)
    32             {
    33                  sum=0;
    34                 for(k=1;k<=m;k++)
    35                 {
    36                     if((i*a[k]+j*b[k])<0) sum++;
    37                     if((i*a[k]+j*b[k])==0) break;
    38                 }
    39                 if(sum==n)
    40                 {
    41                      f=1;
    42                      printf("%d %d
    ",i,j);
    43                      break;
    44                  }
    45              }
    46              if(f==1) break;
    47          }
    48     }
    49     
    50     return 0;
    51 }
    52             
     
  • 相关阅读:
    [Web安全] XXE漏洞攻防学习(中)
    [Web安全] XXE漏洞攻防学习(上)
    [转]kali中eth0网卡突然消失解决方案
    [漏洞复现]CVE-2018-4887 Flash 0day
    [漏洞复现]CVE-2010-2883 Adobe Reader 打开pdf电脑即刻中招
    [漏洞复现] CVE-2017-11882 通杀所有Office版本
    墨菲定律:Mac本硬盘坏了
    独立思考
    阅读书单
    2020未来小思考
  • 原文地址:https://www.cnblogs.com/sxiszero/p/3695301.html
Copyright © 2011-2022 走看看