BAPC K题 Keep Him Inside

alanwade 2020-03-22 原文

BAPC K题 Keep Him Inside

Problem Statement:

As a result of a long-standing war between the Sorcerers and the Orcs, you have been assigned as officer of one of the prison blocks. Recently the leader of the Orcs has been captured and placed inside a special cell. It works as follows: the cell is a convex polygon with at every vertex a guard tower in which a Sorcerer is placed.

Thanks to the recent agreement between the Sorcerers and Orcs, called the Beneficial Activities for Prisoners in Cells, the leader of the Orcs should be able to move around freely in his cell. You do not want your prisoner to escape, so you order the sorcerers to work together on a containment spell. If done right, this creates a magical aura around the prisoner that will prevent him from escaping.

In order for the containment spell to work, all Sorcerers need to channel a certain fraction of their maximum power into the spell such that two things hold:

  • The spell needs to be perfectly balanced: the sum of the fractions of power over all Sorcerers must equal 1.
  • The centre of the spell should coincide with the prisoner. This means that the average of the positions of Sorcerers, weighted by the fraction of power they are channeling, should be the location of the prisoner.

Given the layout of the cell and the location of the prisoner, assign a fraction of power each

Sorcerer should spend so that the containment spell works.

 

Input

  •  The first line contains 3 ≤ n ≤ 10,the number of Sorcerers in guard towers and two

    integers -10≤ x,y ≤ 104, the coordinates of the prisoner.

  • Then follow n lines, each of which contains two integers -10≤ x,y ≤ 104 , the coordinates of a Sorcerer.

 

It is guaranteed that the locations are given in counter clockwise order and form a strictly convex polygon, i.e. no three points lie on a line. The prisoner is located strictly inside the polygon.

 Output

  • Output n lines where the ith line contains a floating point number between 0 and 1inclusive: the fraction of power that the ith Sorcerer should use for the containment spell to work.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e4+5;
ll xa,xb,xc,ya,yb,yc,px,py;
double a,b,c,ans[maxn];
int n;
struct node //用来记录巫师所在点的坐标
{
ll x,y;
}no[20];
int main()
{
cin >> n >> px >> py;   //px,py表示P点的坐标
for(int i = 0 ; i < n ; i++)
cin >> no[i].x >> no[i].y;
xc = no[0].x,yc = no[0].y;
xb = no[1].x,yb = no[1].y;
px -= xc,py -= yc;
xb -= xc,yb -= yc;
for(int i = 2 ; i < n ; i++)
{
xa = xb,ya = yb;
xb = no[i].x,yb = no[i].y;
xb -= xc,yb -= yc;
double f = xb*ya - xa*yb;//表示上述公式中a,b前面的系数
a = (xb*py - px*yb)/f;
b = (px*ya - py*xa)/f;
c = 1 - a - b;
if(a >= 0 && b >= 0 && c >= 0)//要保证计算出的权值全为正,并记录在ans中
{
ans[0] = c; //c对应的是x3也就是这里的xc,对应点的下标为0
ans[i-1] = a; //a对应的是x1也就是这里的xa,对应点的下标为i-1
ans[i] = b; //b对应的是x2也就是这里的xb,对应点的下标为i
}
}
for(int i = 0 ; i < n ; i++)
cout << setprecision(12) << ans[i] << endl;
return 0;
}

 

发表于
2020-03-22 18:06 
Alanwade 
阅读(
评论(
编辑 
收藏

 

版权声明:本文为alanwade原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/alanwade/p/12547415.html

BAPC K题 Keep Him Inside的更多相关文章

  1. 警告: A docBase ** inside the host appBase has been specified, and will be ignored

    错误:警告: A docBase D:\apache-tomcat-6.0.35\webapps\16S in […]...

  2. linux上mysql及keepalived搭建

    master1 10.1.1.14 VIP 10.1.1.16master2 10.1.1.15 VIP 10 […]...

  3. java端通过cxf调用.net端服务 – Keep Running

    java端通过cxf调用.net端服务 今天在项目的过程中,java服务端使用cxf动态调用.net服务的时候 […]...

  4. Unable to preventDefault inside passive event listener due to target being treated as passive

    最近在做Vue项目,做了个swiper,滚动图片时报了个这个警告:         原因: 由于浏览器必须要在 […]...

  5. [Inside HotSpot] 模板解释器

    0. 简介 众所周知,hotspot默认使用解释+编译混合(-Xmixed)的方式执行代码。它首先使用模板解释 […]...

  6. 身份证号码验证工具类 – Keep Running

    身份证号码验证工具类 1:简单的身份证验证可以通过正则表达式进行,不过对于一些要求比较严格的估计就不能胜任了 […]...

  7. centos7上keepalived的安装和配置

    1、环境规划1)master:node1,centos7.5,eth0:192.168.1.11,eht1:1 […]...

  8. 体重控制

    体重控制 理论基础:能力守恒理论,体重控制的第一定律便是保持热量差,即基础代谢与摄入食物热量差为负数,这样就能 […]...

随机推荐

  1. Multisim 14.0 安装教程 – yf.x

    Multisim 14.0 安装教程 1.  安装环境:      win 7 64bit + Multisi […]...

  2. 鸿蒙软总线跨设备访问该怎么玩——小总结

    为了遵守相关法律法规,合法合规运营,网站进行全面整改,整改工作于2021年3月18日12:00开始,预计于3月 […]...

  3. 批量插入数据

    项目需求:浏览器中访问django后端某一条url(如:127.0.0.1:8080/get_book/),实 […]...

  4. Vue-Router原理分析-路由模式和install

      单页应用(SPA, Single Page Application)的整个Web系统由一个html文件,通 […]...

  5. 软件设计入门1 架构设计

    热爱编程才能做优秀的软件设计师! 软件设计有一些方法可以参考。但更重要的是要有好的需求分析、丰富的技术知识和设 […]...

  6. systemverilog学习(9)assertion

    一:初实assertion   断言就是一段描述设计期望行为的代码。 目前, 对断言的使用主要在于仿真, 但断 […]...

  7. python系列一——python特点以及和java不同的运行机制

    一、python特点:       1)高级       2)面向对象       3)可升级       4 […]...

  8. bootstrap的字体设置

    @font-face { font-family: \'Glyphicons Halflings\'; src […]...

展开目录

目录导航