当前位置:   article > 正文

Code[VS]1273 风战_codevs 1273

codevs 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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/924037
推荐阅读
相关标签
  

闽ICP备14008679号