Code[VS]1273 风战

原题链接:http://codevs.cn/problem/1273/

风战

题目描述 Description

Colonel Trapp is trapped! For several days he has been fighting General Position on a plateau and his mobile command unit is now stuck at (0, 0), on the edge of a cliff. But the winds are changing! The Colonel has a secret weapon up his sleeve: the “epsilon net.” Your job, as the Colonel’s chief optimization officer, is to determine the maximum advantage that a net can yield.

上校陷入了困境!几天以来他一直在高原上战斗并且它的移动指挥单位现在停留在将军位置(0,0),悬崖边上。但是风是在变的!上校有一个秘密武器在他的袖子上:E网(希腊字母epsilon)。作为上校的最优方案工作员,你的工作,就是确定最优的网,使敌人投降。

The epsilon net is a device that looks like a parachute, which you can launch to cover any convex shape. (A shape is convex when, for every pair p,q of points it contains, it also contains the entire line segment pq.) The net shape must include the launch point (0,0).

E网是一个像降落伞的装置,你可以把它弄成任何凸多边形。

The General has P enemy units stationed at fixed positions and the Colonel has T friendly units. The advantage of a particular net shape equals the number of enemy units it covers, minus the number of friendly units it covers. The General is not a unit.

这个高地有P个敌人单位驻扎在固定的地点,上校有T个友军单位。最好的网的形状应该使得它能覆盖的敌人单位数减去自己人单位数的值最大。将军不是个单位。

You can assume that • no three points (Trapp’s position (0,0), enemy units, and friendly units) lie on a line, • every two points have distinct x-coordinates and y-coordinates, • all co-ordinates (x,y) of the units have y > 0, • all co-ordinates are integers with absolute value at most 1000000000, and • the total number P + T of units is between 1 and 100.

你可以假设没有三个点在同一线上,每两个点有明确的横纵坐标,所有单位纵坐标大于0,所有坐标都是整数绝对值最大1000000000,并且单位总数在1到100之间。

输入描述 Input Description

The first line contains P and then T, separated by spaces. Subsequently there are P lines of the form xy giving the enemy units’ co-ordinates, and then T lines giving the friendly units’ co- ordinates.

输入会是P,T。然后P行敌人坐标,T行友军坐标

输出描述 Output Description

Output a single line with the maximum possible advantage.

输出仅一行,表示最优解。

样例输入 Sample Input

5 3
-8 4
-7 11
4 10
10 5
8 2
-5 7
-4 3
5 6

样例输出 Sample Output

3

题解

题目翻译有误,凸多边形必须包含原点
由于数据量很小,我们可以O(n^2)暴力枚举所有顶点为原点的三角形,O(n)计算三角形中敌人数减去友军数的值,再进行O(n^3)的DP即可AC。  

代码
#include<bits/stdc++.h>
#define db double
using namespace std;
const int M=1005;
struct pt{int x,y,t;db k;};
bool operator <(pt a,pt b){return a.k<b.k;}
pt operator -(pt a,pt b){return (pt){a.x-b.x,a.y-b.y};}
long long operator *(pt a,pt b){return 1ll*a.x*b.y-1ll*a.y*b.x;}
pt p[M];
int n,m,trag[M][M],dp[M][M];
void in()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
    scanf("%d%d",&p[i].x,&p[i].y),p[i].t=1,p[i].k=atan2(p[i].y,p[i].x);
    for(int i=1;i<=m;++i)
    scanf("%d%d",&p[i+n].x,&p[i+n].y),p[i+n].t=-1,p[i+n].k=atan2(p[i+n].y,p[i+n].x);
    n+=m;
}
void ac()
{
    int ans=0;
    sort(p+1,p+1+n);
    for(int i=1;i<=n;++i)
    for(int j=i+1;j<=n;++j)
    for(int k=i+1;k<j;++k)
    if((p[i]-p[k])*(p[j]-p[k])>0)
    trag[i][j]+=p[k].t;
    for(int i=1;i<=n;++i)
    {
        dp[i][0]=p[i].t;
        for(int j=1;j<i;++j)
        for(int k=0;k<j;++k)
        if((p[k]-p[i])*(p[j]-p[i])>0)
        dp[i][j]=max(dp[i][j],dp[j][k]+trag[j][i]+p[i].t);
    }
    for(int i=1;i<=n;++i)
    for(int j=1;j<i;++j)
    ans=max(ans,dp[i][j]);
    printf("%d",ans);
}
int main()
{
    in();
    ac();
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值