ZOJ 3450 Doraemon's Railgun

Doraemon's Railgun Time Limit: 2 Seconds       Memory Limit: 65536 KB ZOJ 3450 Doraemon's Railgun_第1张图片

Doraemon's city is being attacked again. This time Doraemon has built a powerful railgun in the city. So he will use it to attack enemy outside the city.

There are N groups of enemy. Now each group is staying outside of the city. Group i is located at different (XiYi) and contains Wi soldiers. After T0 days, all the enemy will begin to attack the city. Before it, the railgun can fire artillery shells to them.

The railgun is located at (X0, Y0), which can fire one group at one time, The artillery shell will fly straightly to the enemy. But in case there are several groups in a straight line, the railgun can only eliminate the nearest one first if Doraemon wants to attack further one. It took Ti days to eliminate group i. Now please calculate the maximum number of soldiers it can eliminate.

Input

There are multiple cases. At the first line of each case, there will be four integers, X0, Y0N, T0 (-1000000000 ≤ X0, Y0 ≤ 1000000000; 1 ≤ N ≤ 500; 1 ≤ T0 ≤ 10000). Next N lines follow, each line contains four integers, XiYiTiWi (-1000000000 ≤ XiYi ≤ 1000000000; 0 ≤ TiWi ≤ 10000).

Output

For each case, output one integer, which is the maximum number of soldiers the railgun can eliminate.

Sample Input

0 0 5 10
0 5 2 3
0 10 2 8
3 2 4 6
6 7 3 9
4 4 10 2

Sample Output

20

题意:城里有一个炮台,城外有n个敌军,告诉炮台的坐标,N个敌军的坐标,打掉每个敌军需要 ti 的时间,可以得到 wi 点好处,对于以炮台为起点在同一条射线上的敌军,要先打前面的,才能打后面的,问在T时间内,最多可以获得多少好处。


思路:先处理一下,然后分组背包。主要是要把在一条射线上的先处理好,后面就比较好办。还有一点就是,数据存在可能t都是0的情况,要注意处理好。

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
const int N = 1009;
typedef long long ll;

using namespace std;

struct Node
{
    ll x,y;
    int t,w;
}f[N];

int vis[N];
int dp[10090];

bool cmp(Node a,Node b)
{
    return a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y;
}

bool check(int i,int j)
{
    if(f[i].x*f[j].y==f[i].y*f[j].x)
    return f[i].x*f[j].x>=0 && f[i].y*f[j].y>=0;

    return false;
}

int main()
{
    ll x0,y0;
    int T;
    int n;

    while(~scanf("%lld%lld%d%d",&x0,&y0,&n,&T))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%lld%lld%d%d",&f[i].x,&f[i].y,&f[i].t,&f[i].w);
            f[i].x-=x0;
            f[i].y-=y0;
        }
        sort(f,f+n,cmp);
        memset(vis,0,sizeof vis);
        vector<Node>e[N];

        for(int i=0;i<n;i++)
        {
            if(vis[i])continue;
            e[i].push_back(f[i]);
            for(int j=i+1;j<n;j++)
            {
               if(check(i,j))
               {
                   vis[j]=1;
                   int s=e[i].size()-1;

                   if(f[j].t==0)//处理t=0的情况
                   e[i][s].w+=f[j].w;
                   else
                   {
                       e[i].push_back(f[j]);
                       e[i][s+1].w+=e[i][s].w;
                       e[i][s+1].t+=e[i][s].t;
                   }
               }
            }
        }
        memset(dp,0,sizeof dp);

        for(int i=0;i<n;i++)
        {
            for(int j=T;j>=0;j--)
            {
                for(int k=0; k<e[i].size() && e[i][k].t<=j ;k++)
                dp[j]=max( dp[j] , dp[j-e[i][k].t]+e[i][k].w );
            }
        }
        printf("%d\n",dp[T]);
    }

    return 0;
}







你可能感兴趣的:(ZOJ 3450 Doraemon's Railgun)