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+;
ll xa,xb,xc,ya,yb,yc,px,py;
double a,b,c,ans[maxn];
int n;
struct node //用来记录巫师所在点的坐标
{
ll x,y;
}no[];
int main()
{
cin >> n >> px >> py;   //px,py表示P点的坐标
for(int i = ; i < n ; i++)
cin >> no[i].x >> no[i].y;
xc = no[].x,yc = no[].y;
xb = no[].x,yb = no[].y;
px -= xc,py -= yc;
xb -= xc,yb -= yc;
for(int i = ; 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 = - a - b;
if(a >= && b >= && c >= )//要保证计算出的权值全为正,并记录在ans中
{
ans[] = c; //c对应的是x3也就是这里的xc,对应点的下标为0
ans[i-] = a; //a对应的是x1也就是这里的xa,对应点的下标为i-1
ans[i] = b; //b对应的是x2也就是这里的xb,对应点的下标为i
}
}
for(int i = ; i < n ; i++)
cout << setprecision() << ans[i] << endl;
return ;
}

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

  1. hdu5080:几何+polya计数(鞍山区域赛K题)

    /* 鞍山区域赛的K题..当时比赛都没来得及看(反正看了也不会) 学了polya定理之后就赶紧跑来补这个题.. 由于几何比较烂写了又丑又长的代码,还debug了很久.. 比较感动的是竟然1Y了.. * ...

  2. 2017Summmer_上海金马五校 F题,G题,I题,K题,J题

    以下题目均自己搜 F题  A序列 一开始真的没懂题目什么意思,还以为是要连续的子串,结果发现时序列,简直智障,知道题意之后,好久没搞LIS,有点忘了,复习一波以后,直接双向LIS,处理处两个数组L和R ...

  3. 2020牛客多校第八场K题

    __int128(例题:2020牛客多校第八场K题) 题意: 有n道菜,第i道菜的利润为\(a_i\),且有\(b_i\)盘.你要按照下列要求给顾客上菜. 1.每位顾客至少有一道菜 2.给顾客上菜时, ...

  4. 2019牛客暑期多校训练营(第四场)k题、j题

    传送门 k题: 题意: 给你一串由数字构成的字符串,你从这个字符串中找子字符串使这个字符串是300的倍数 题解: 这道题和第三场的B题极其相似 首先可以把是三百的倍数分开,必须要是100和3的倍数 是 ...

  5. ZOJ 3879 Capture the Flag 15年浙江省赛K题

    每年省赛必有的一道模拟题,描述都是非常的长,题目都是蛮好写的... sigh... 比赛的时候没有写出这道题目 :( 题意:首先输入4个数,n,q,p,c代表有n个队伍,q个服务器,每支队伍的初始分数 ...

  6. 2016 ICPC青岛站---k题 Finding Hotels(K-D树)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5992 Problem Description There are N hotels all over ...

  7. 2013 南京邀请赛 K题 yet another end of the world

    /** 大意:给定一组x[],y[],z[] 确定有没有两个不同的x[i], x[j] 看是否存在一个ID使得 y[i]<=ID%x[i]<=z[i] y[j]<=ID%x[j]&l ...

  8. hdu 4463 有一条边必须加上 (2012杭州区域赛K题)

    耐克店 和 苹果店必须相连 Sample Input42 30 01 00 -1 1 -10 Sample Output3.41 # include <iostream> # includ ...

  9. 陕西师范第七届K题----动态规划

    ps: 自己的方法绝对是弱爆了 肯定存在更优的方法 O(n^3)复杂度 暴力求解的.. 链接:https://www.nowcoder.com/acm/contest/121/K来源:牛客网 柯怡最近 ...

随机推荐

  1. cisco WLC开启portal认证,但是访问https无法跳转问题的解决

     config network web-auth https-redirect enable版本8,及以上才支持  官方文档: http://www.cisco.com/c/zh_cn/support ...

  2. IOS下的safari下localStorage不起作用的问题

    我们的一个小应用,使用百度地图API获取到用户的坐标之后用localStorage做了下缓存,测试上线之后有运营同学反馈页面数据拉取不到, 测试的时候没有发现问题,而且2台相同的iphone一台可以一 ...

  3. 配置Maven本地仓库

    以本机为例: 系统:Windows 开发工具:IDEA 如果想在dos窗口输mvn命令,需配置环境变量. 1. 在D盘新建repository文件夹,该目录用作maven的本地库. 2. 打开D:\P ...

  4. 烧光百亿的共享单车行业,ofo和摩拜到底该不该合并?

    共享经济领域可谓一地鸡毛,除了众多不靠谱的跟风项目外--共享马扎."老公寄存屋",更多的是不绝于耳的倒闭消息.尤其是在共享单车行业,暂且不提那些体量小的项目,单单是倒闭的大型共享单 ...

  5. WiFi产生电磁辐射或让人想去自杀

    随着互联网在生活中的地位越来越重要,WiFi作为一种无线连接方式给了用户极大的便捷,然而有一部分科学家提出WiFi产生的电磁反应会对人的健康受到影响.面对这种说法,我们一直以为是专家在危言耸听,但是如 ...

  6. Hellc

    [题目描述] 作为一个生活散漫的人,小 Z 每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小 Z 再也无法忍受这恼人的找袜子过程,于是他决定听天由命-- 具体来说,小 Z 把这 ...

  7. 为什么要用location的hash来传递参数?

    分页功能代码实现 <div> <a class="btn" href="#" style="..." @Click.pre ...

  8. 【基础篇】hexo博客搭建教程

    [基础篇]搭建hexo博客(一) 作者:Huanhao bilibili:Mrhuanhao 前言 你是否想拥有属于自己的博客?你是否无奈与自己不会写网站而烦恼? 不要担心,本系列教程将会实现你白嫖的 ...

  9. 泰拉瑞亚Linux主机打造指南

    最近玩了泰拉瑞亚,一个2D版的我的世界,但苦于steam的联机太过不靠谱,经常会出现和朋友之间联机失败的问题,所以我把服务器放到了部署我博客的服务器,这样就可以通过IP直接让好友加入游戏了! 首先是购 ...

  10. C#连接Informix数据库

    最近在工作中遇到了需要连接Informix数据库的问题,在通过研究后发现了可以通过多种方式实现,我选择的是通过IBM Informix .NET Provider.该方式需要引用IBM.Data.In ...