郭大侠与Rabi-Ribi

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

最近郭大侠迷上了玩Rabi-Ribi这个游戏。

Rabi-Ribi呢,是一个打兔子的动作冒险游戏,萌萌哒的兔子在地上跑来跑去,好萌好萌呀~

这个游戏是这样玩的,郭大侠作为一个主角,拿着一个小锤子,他的目标是敲晕兔子,然后最后把这些敲晕的兔子都带回家。

当然咯,郭大侠想带回的兔子的总价值最高~

但是,兔子实在是太多了,郭大侠的锤子每一秒钟只能敲晕一只兔子,而且每一只兔子只会在地面上逗留a[i]a[i]秒,在a[i]a[i]秒之后,这一只兔子就会跑回自己的小窝里面。

所以郭大侠面临一些抉择,希望你能帮助他。

Input

第一行包含一个整数NN表示有NN个兔子在地上跑来跑去。

第二行NN个用空格分隔的整数a[i]a[i]表示第i只兔子冒出后停留的时间

第三行NN个用空格分隔的整数v[i]v[i]表示第i只兔子的价值。

1≤N≤1000001≤N≤100000

1≤a[i]≤50001≤a[i]≤5000

1≤v[i]≤10001≤v[i]≤1000

Output

输出郭大侠最多能获得的价值是多少

Sample input and output

Sample Input Sample Output
5
5 3 6 1 4
7 9 2 1 5
24
3
1 1 1
1 2 3
3

Hint

死宅真可怕,连可爱的兔子都要敲晕带回家 QAQ

思路:这题的数据水;在某个时间点,放入能放的最大值;倒着写;    

   下面是三种不一样的解法;

暴力:纯暴力,因为数据水所以过了;

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define inf 0xfffffff
struct is
{
int w,v;
}a[];
int cmp(is x,is y)
{
if(x.v!=y.v)
return x.v>y.v;
return x.w>y.w;
}
int flag[];
int check(int x)
{
for(int i=x;i>;i--)
if(!flag[i])
return i;
return -;
}
int main()
{
int x,y,z,i,t;
while(~scanf("%d",&x))
{
memset(flag,,sizeof(flag));
for(i=;i<x;i++)
scanf("%d",&a[i].w);
for(i=;i<x;i++)
scanf("%d",&a[i].v);
sort(a,a+x,cmp);
int kui=;
for(i=;i<x;i++)
{
int gg=check(a[i].w);
if(gg!=-)
{
flag[gg]=;
kui+=a[i].v;
}
}
printf("%d\n",kui);
}
return ;
}

线段树:线段树维护+二分查找

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define esp 0.00000000001
const int N=2e5+,M=1e6+,inf=1e9;
struct is
{
int x,y;
}a[N];
int ans[N];
int cmp(is x,is y)
{
if(x.y!=y.y)
return x.y>y.y;
return x.x>y.x;
}
int minn[N];
void update(int p,int c,int l,int r,int pos)
{
if(p==l&&p==r)
{
minn[pos]=c;
return;
}
int mid=(l+r)>>;
if(p<=mid)
update(p,c,l,mid,pos<<);
if(p>mid)
update(p,c,mid+,r,pos<<|);
minn[pos]=min(minn[pos<<],minn[pos<<|]);
}
int query(int L,int R,int l,int r,int pos)
{
if(L<=l&&R>=r)
return minn[pos];
int mid=(l+r)>>;
int ans=inf;
if(L<=mid)
ans=min(ans,query(L,R,l,mid,pos<<));
if(R>mid)
ans=min(ans,query(L,R,mid+,r,pos<<|));
return ans;
}
int getpos(int x)
{
int st=;
int en=x;
if(query(st,en,,,)!=)
return -;
while(st<en)
{
int mid=(st+en)>>;
if(query(mid+,en,,,)!=)
en=mid;
else
st=mid+;
}
if(query(st,st,,,)==)
return st;
if(query(st+,st+,,,)==)
return st+;
}
int main()
{
int x,y,z,i,t;
while(~scanf("%d",&x))
{
memset(ans,,sizeof(ans));
memset(minn,,sizeof(minn));
for(i=;i<=x;i++)
scanf("%d",&a[i].x);
for(t=;t<=x;t++)
scanf("%d",&a[t].y);
sort(a+,a+x+,cmp);
for(i=;i<=x;i++)
{
int pos=getpos(a[i].x);
if(pos>&&ans[pos]==)
{
update(pos,a[i].y,,,);
ans[pos]=a[i].y;
}
}
int sum=;
for(i=;i<=;i++)
sum+=ans[i];
printf("%d\n",sum);
}
return ;
}

优先队列:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define esp 0.00000000001
const int N=2e5+,M=1e6+,inf=1e9;
struct is
{
int x,y;
}a[N];
int ans[N];
int cmp(is x,is y)
{
return x.x>y.x;
}
int main ()
{
int x,y,z,i,t;
while(~scanf("%d",&x))
{
for(i=;i<=x;i++)
scanf("%d",&a[i].x);
for(t=;t<=x;t++)
scanf("%d",&a[t].y);
sort(a+,a+x+,cmp);
priority_queue<int>q;
int flag=,ans=;
for(i=;i>=;i--)
{
while(a[flag].x>=i)
q.push(a[flag].y),flag++;
if(!q.empty())
ans+=q.top(),q.pop();
}
printf("%d\n",ans);
}
return ;
}

郭大侠与Rabi-Ribi

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

最近郭大侠迷上了玩Rabi-Ribi这个游戏。

Rabi-Ribi呢,是一个打兔子的动作冒险游戏,萌萌哒的兔子在地上跑来跑去,好萌好萌呀~

这个游戏是这样玩的,郭大侠作为一个主角,拿着一个小锤子,他的目标是敲晕兔子,然后最后把这些敲晕的兔子都带回家。

当然咯,郭大侠想带回的兔子的总价值最高~

但是,兔子实在是太多了,郭大侠的锤子每一秒钟只能敲晕一只兔子,而且每一只兔子只会在地面上逗留a[i]a[i]秒,在a[i]a[i]秒之后,这一只兔子就会跑回自己的小窝里面。

所以郭大侠面临一些抉择,希望你能帮助他。

Input

第一行包含一个整数NN表示有NN个兔子在地上跑来跑去。

第二行NN个用空格分隔的整数a[i]a[i]表示第i只兔子冒出后停留的时间

第三行NN个用空格分隔的整数v[i]v[i]表示第i只兔子的价值。

1≤N≤1000001≤N≤100000

1≤a[i]≤50001≤a[i]≤5000

1≤v[i]≤10001≤v[i]≤1000

Output

输出郭大侠最多能获得的价值是多少

Sample input and output

Sample Input Sample Output
5
5 3 6 1 4
7 9 2 1 5
24
3
1 1 1
1 2 3
3

Hint

死宅真可怕,连可爱的兔子都要敲晕带回家 QAQ

cdoj 1334 郭大侠与Rabi-Ribi 贪心+数据结构的更多相关文章

  1. cdoj 1334 郭大侠与Rabi-Ribi Label:贪心+数据结构

    郭大侠与Rabi-Ribi Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) 最近 ...

  2. cdoj 1342 郭大侠与甲铁城 树状数组+离线

    郭大侠与甲铁城 Time Limit: 1500/800MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit St ...

  3. CDOJ 1284 苦恼的郭大侠 map启发式合并

    苦恼的郭大侠 题目连接: http://acm.uestc.edu.cn/#/problem/show/1284 Description 花开雷霆崖,血染伊吕波. 公元1772年. 郭大侠终于照着天行 ...

  4. cdoj1334郭大侠与Rabi-Ribi

    地址:http://acm.uestc.edu.cn/#/problem/show/1334 题目: 郭大侠与Rabi-Ribi Time Limit: 3000/1000MS (Java/Other ...

  5. cdoj1342郭大侠与甲铁城

    地址:http://acm.uestc.edu.cn/#/problem/show/1342 题目: 郭大侠与甲铁城 Time Limit: 1500/800MS (Java/Others)     ...

  6. cdoj1339郭大侠与线上游戏

    地址:http://acm.uestc.edu.cn/#/problem/show/1339 题目: 郭大侠与线上游戏 Time Limit: 6000/2000MS (Java/Others)    ...

  7. cdoj1338郭大侠与英雄学院

    地址:http://acm.uestc.edu.cn/#/problem/show/1338 思路: 郭大侠与英雄学院 Time Limit: 6000/2000MS (Java/Others)    ...

  8. cdoj1337郭大侠与阴阳家

    地址:http://acm.uestc.edu.cn/#/problem/show/1337 思路: 郭大侠与阴阳家 Time Limit: 3000/4000MS (Java/Others)     ...

  9. 郭大侠与Rabi-Ribi (优先队列)

    最近郭大侠迷上了玩Rabi-Ribi这个游戏. Rabi-Ribi呢,是一个打兔子的动作冒险游戏,萌萌哒的兔子在地上跑来跑去,好萌好萌呀~ 这个游戏是这样玩的,郭大侠作为一个主角,拿着一个小锤子,他的 ...

随机推荐

  1. Leetcode#89 Gray Code

    原题地址 二进制码 -> 格雷码:从最右边起,依次与左边相邻位异或,最左边一位不变.例如: 二进制: 1 0 0 1 1 1 0 |\|\|\|\|\|\| 格雷码: 1 1 0 1 0 0 1 ...

  2. PE文件之资源讲解

    资源是PE文件中非常重要的部分,几乎所有的PE文件中都包含资源,与导入表与导出表相比,资源的组织方式要复杂得多,要了解资源的话,重点在于了解资源整体上的组织结构. 我们知道,PE文件资源中的内容包括: ...

  3. javascript设计模式-抽象工厂模式

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Google NACL 简介

    Back to README Getting Started This page tells you how to install Native Client and run demos, both ...

  5. HDU 4572 Bottles Arrangement(找规律,仔细读题)

    题目 //找规律,123321123321123321…发现这样排列恰好可以错开 // 其中注意题中数据范围: M是行,N是列,3 <= N < 2×M //则猜测:m,m,m-1,m-1 ...

  6. .htaccess文件的作用(访问控制)

    在线工具: http://www.htaccesseditor.com/sc.shtml 说到.htaccess文件,我想对于wordpress新手或者老手都应该不是很熟悉,也没有多少这方面的概念吧, ...

  7. C#编程使用Managed Wifi API连接无线SSID

    C#编程使用Managed Wifi API连接无线SSIDhttp://www.2cto.com/kf/201307/227623.html Managed Wifi API - Homehttp: ...

  8. SQL Server 中的存储过程

    一:初步了解存储过程的使用 创建一个简单的存储过程 CREATE PROC spEmployee AS SELECT * FROM HumanResources.Employee; 执行这个存储过程: ...

  9. Project Euler 107:Minimal network 最小网络

    Minimal network The following undirected network consists of seven vertices and twelve edges with a ...

  10. Android核心分析之十九电话系统之GSMCallTacker

    GSMCallTracker在本质上是一个Handler.<IGNORE_JS_OP> 1.jpg (1.52 KB, 下载次数: 1) 下载附件  保存到相册 2012-3-22 11: ...