若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1213: Friend or Foe?

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,924

题目描述

Luke has a bit of trouble telling the difference between star systems in the Rebel Alliance and those in the Empire. He has a list of the x,y,z coordinates of each system in the Empire and each in the Alliance, but at warp speed he simply has insufficient time to look up systems in his lists.
After destroying the friendly planet Endor, Luke has had to admit he needs the help of his targeting computer. His computer, being an early model, can only compute the truth value of the inequality

ax + by + cz + d > 0

Where x,y,z are the coordinates of the system, and a,b,c,d are real-valued coefficients. You are to compute a,b,c,d so that the inequality holds for all systems in the Empire, and for no systems in the Alliance.
Input consists of several test cases followed by -1 -1. Each test case first gives the number of Alliance systems, followed by a line for each system giving the integer coordinates -100 ≤ x,y,z ≤ 100 of the system in 3-dimensional space. The number of Empire systems, and the coordinates of each, follow. The Empire and Alliance combined have at least one and no more than 200 systems. All systems have distinct coordinates.
For each test case, output a single line containing a,b,c,d as real numbers separated by spaces. Use enough precision to ensure that your solution is correct. You may assume that a solution exists; if there is more than one solution, any one will do.

输入

暂无

输出

暂无

样例输入

2
-93 48 -92
-62 12 -32
8
51 98 -61
-3 72 81
95 25 22
89 43 -99
100 -2 -96
-18 45 -63
36 -21 -8
71 -24 42
-1 -1

样例输出

83.000000 65.000000 -27.000000 -62.000000

参考代码

#include <stdio.h>
int x[20];
int y[20];
int r[20];
int dsq(int i, int j) 
{
    return i*i + j*j;
}
int hits(int i, int j) 
{
    return dsq(x[i]-x[j], y[i]-y[j]) <= dsq(r[i]+r[j],0);
}
main() 
{
    int CASES;
    scanf("%d", &CASES);
    while(CASES--) 
    {
        int c,i,j,k;
        int mx = 0;
        scanf("%d", &c);
        for (i=0;i<c;i++) 
        {
            scanf("%d %d %d", x+i,y+i, r+i);
        }
        for (i=0;i<(1<<c);i++) 
        {
            int tota = 0;
            for (j=0;j<c;j++) 
            {
                if(!(i & (1<<j))) continue;
                tota += r[j]*r[j];
                for (k=0;k<c;k++) 
                {
                    if(j==k) continue;
                    if(!(i & (1<<k))) continue;
                    if(hits(j,k)) goto blah;
                }
            }
            if(tota > mx) mx = tota;
            blah:;
        }
        printf("%dn", mx);
    }
}

解析

暂无

hustoj

发表评论 取消回复

要发表评论,您必须先登录。


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

原站点 Skip Dreams孤独患者
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist