亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

hdu 4970 Killing Monsters

系統 1912 0

Killing Monsters

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 160????Accepted Submission(s): 86


Problem Description
Kingdom Rush is a popular TD game, in which you should build some towers to protect your kingdom from monsters. And now another wave of monsters is coming and you need again to know whether you can get through it.

The path of monsters is a straight line, and there are N blocks on it (numbered from 1 to N continuously). Before enemies come, you have M towers built. Each tower has an attack range [L, R], meaning that it can attack all enemies in every block i, where L<=i<=R. Once a monster steps into block i, every tower whose attack range include block i will attack the monster once and only once. For example, a tower with attack range [1, 3] will attack a monster three times if the monster is alive, one in block 1, another in block 2 and the last in block 3.

A witch helps your enemies and makes every monster has its own place of appearance (the ith monster appears at block Xi). All monsters go straightly to block N.

Now that you know each monster has HP Hi and each tower has a value of attack Di, one attack will cause Di damage (decrease HP by Di). If the HP of a monster is decreased to 0 or below 0, it will die and disappear.
Your task is to calculate the number of monsters surviving from your towers so as to make a plan B.
?

Input
The input contains multiple test cases.

The first line of each case is an integer N (0 < N <= 100000), the number of blocks in the path. The second line is an integer M (0 < M <= 100000), the number of towers you have. The next M lines each contain three numbers, Li, Ri, Di (1 <= Li <= Ri <= N, 0 < Di <= 1000), indicating the attack range [L, R] and the value of attack D of the ith tower. The next line is an integer K (0 < K <= 100000), the number of coming monsters. The following K lines each contain two integers Hi and Xi (0 < Hi <= 10^18, 1 <= Xi <= N) indicating the ith monster’s live point and the number of the block where the ith monster appears.

The input is terminated by N = 0.
?

Output
Output one line containing the number of surviving monsters.
?

Sample Input
        
5 2 1 3 1 5 5 2 5 1 3 3 1 5 2 7 3 9 1 0
?

Sample Output
        
3
Hint
In the sample, three monsters with origin HP 5, 7 and 9 will survive.
?

Source
?


題解及代碼:


官方的思路挺好:

hdu 4970 Killing Monsters


比賽的時候開始使用線段樹來做,結果超時,然后換成樹狀數組來做,使用樹狀數組維護區間和,感覺和官方思路還是差上一線啊。

官方:

      #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#define maxn 100010
using namespace std;
typedef long long ll;

ll delta[maxn];

int main()
{
    int n,m,l,r;
    ll v;
    while(scanf("%d",&n)&&n)
    {
        memset(delta,0,sizeof(delta[0])*(n+5));
        scanf("%d",&m);
        for(int i=0;i<m;i++)
        {
           scanf("%d%d%I64d",&l,&r,&v);
           delta[l]+=v;
           delta[r+1]-=v;
        }
        for(int i=2;i<=n;i++)
        {
            delta[i]+=delta[i-1];
        }
        for(int i=n-1;i>=1;i--)
        {
            delta[i]+=delta[i+1];
        }
        int ans=0;
        scanf("%d",&m);
        for(int i=0;i<m;i++)
        {
            scanf("%I64d%d",&v,&r);
            if(v>delta[r])
                ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

    


個人思路:

      #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#define INF 99999999
typedef long long LL;
using namespace std;

const int MAX=100000+100;
LL n;
LL c1[MAX],c2[MAX];

LL lowbit(LL x)
{
    return x&(-x);
}

void Update(LL x,LL d,LL *c)
{
    while(x<=n)
    {
        c[x]+=d;
        x+=lowbit(x);
    }
}

LL Query(LL x,LL *c)
{
    LL sum=0;
    while(x>0)
    {
        sum+=c[x];
        x-=lowbit(x);
    }
    return sum;
}

int main()
{
    LL x,y,d,t,h;
    int m;
    while(scanf("%I64d",&n)&&n)
    {
        memset(c1,0,sizeof c1);
        memset(c2,0,sizeof c2);
        scanf("%d",&m);
        for(int i=0; i<m; i++)
        {
            scanf("%I64d%I64d%I64d",&x,&y,&d);
            Update(x,d,c1);
            Update(y+1,-d,c1);
            Update(x,x*d,c2);
            Update(y+1,-(y+1)*d,c2);
        }
        scanf("%d",&m);
        int ans=0;
        for(int i=0; i<m; i++)
        {
            scanf("%I64d%I64d",&h,&x);
            t=Query(n,c1)*(n+1)-Query(x-1,c1)*x-Query(n,c2)+Query(x-1,c2);
            if(h>t) ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}
    






hdu 4970 Killing Monsters


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 精品国产一区二区三区免费 | 国产香蕉98碰碰久久人人 | 久久国产香蕉一区精品 | 4虎最新| 久久99国产乱子伦精品免 | 久久久www成人免费精品 | 亚洲色中文字幕在线播放 | 777精品成人影院 | 在线看欧美三级中文经典 | 免费区欧美一级毛片 | 在线资源站 | 久久九色综合九色99伊人 | 国产www在线观看 | 久久亚洲一级毛片 | 99热在线这里只有精品 | 亚洲欧美日本在线观看 | 中文字幕日韩高清 | 国产福利视频在线观看 | 337p色噜噜| 精品精品国产自在久久高清 | 久久久综合香蕉尹人综合网 | 久久天堂成人影院 | 中文字幕第一页亚洲 | 377p欧洲最大胆艺术 | 国产精品短篇二区 | 一级黄片一级毛片 | 国产精品高清在线观看93 | 在线观看免费黄色小视频 | 亚洲欧美色综合大色 | 欧美激情亚洲精品日韩1区2区 | 亚洲精品乱码久久久久久v 亚洲精品乱码久久久久久麻豆 | 毛片在线不卡 | 99国产高清久久久久久网站 | 777奇米影视久久激情日韩欧美 | 一线视频日本 | 久久中文字幕不卡一二区 | 国产精品久久久久久久久久日本 | 大乳孕妇一级毛片 | 久久天天躁夜夜躁狠狠躁2015 | 成人久久18免费网站游戏 | 2021久久精品永久免费 |