博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 4620 Fruit Ninja Extreme
阅读量:6343 次
发布时间:2019-06-22

本文共 4233 字,大约阅读时间需要 14 分钟。

Fruit Ninja Extreme

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 880    Accepted Submission(s): 231
Special Judge
Problem Description
Cut or not to cut, it is a question.
In Fruit Ninja, comprising three or more fruit in one cut gains extra bonuses. This kind of cuts are called bonus cuts.
Also, performing the bonus cuts in a short time are considered continual, iff. when all the bonus cuts are sorted, the time difference between every adjacent cuts is no more than a given period length of W.
As a fruit master, you have predicted the times of potential bonus cuts though the whole game. Now, your task is to determine how to cut the fruits in order to gain the most bonuses, namely, the largest number of continual bonus cuts.
Obviously, each fruit is allowed to cut at most once. i.e. After previous cut, a fruit will be regarded as invisible and won't be cut any more.
In addition, you must cut all the fruit altogether in one potential cut. i.e. If your potential cut contains 6 fruits, 2 of which have been cut previously, the 4 left fruits have to be cut altogether.
 

 

Input
There are multiple test cases.
The first line contains an integer, the number of test cases.
In each test case, there are three integer in the first line: N(N<=30), the number of predicted cuts, M(M<=200), the number of fruits, W(W<=100), the time window.
N lines follows.
In each line, the first integer Ci(Ci<=10) indicates the number of fruits in the i-th cuts.
The second integer Ti(Ti<=2000) indicate the time of this cut. It is guaranteed that every time is unique among all the cuts.
Then follow Ci numbers, ranging from 0 to M-1, representing the identifier of each fruit. If two identifiers in different cuts are the same, it means they represent the same fruit.
 

 

Output
For each test case, the first line contains one integer A, the largest number of continual bonus cuts.
In the second line, there are A integers, K1, K2, ..., K_A, ranging from 1 to N, indicating the (Ki)-th cuts are included in the answer. The integers are in ascending order and each separated by one space. &#160;If there are multiple best solutions, any one is accepted.
 

 

Sample Input
1 4 10 4 3 1 1 2 3 4 3 3 4 6 5 3 7 7 8 9 3 5 9 5 4
 

 

Sample Output
3 1 2 3
 

 

Source
 
题意:
水果忍者模型。
N表示以下共有 N种切水果的方式。
M表示有M个水果需要你切。
W表示两次连续连击之间最大的间隔时间
然后下N行描述的是 N种切法
第一个数字C表示这种切法可以切多少个水果。
第二个数字表示这种切法所处在的时间。
后C个数字表示此时这种切法所切掉的水果编号。
注意:同时切3个以上才表示连击,一个水果最多只能切一次
思路:
按时间从小到大排序后,从前往后搜,不用回溯。
剪枝:
当前连击数+剩下能够切的次数<=ans时就不用搜了。
感想:
哎,没玩过水果忍者,比赛时把题意读错了。衰~   题意读懂后就是一般的搜索题了,其实不想写博客的,hdu上首次排名第一,纪念一下吧。
代码:
#include 
#include
#include
#include
#define maxn 31using namespace std;int n,m,w,ans,num;int a[maxn],ansa[maxn];bool app[201];struct Node{ int id,cnt,time; int v[11];} pp[maxn];bool cmp(const Node&xx,const Node&yy){ return xx.time
n) return ; if(pp[pos].time-pretime<=w) { t=0; for(i=1; i<=pp[pos].cnt; i++) { if(app[pp[pos].v[i]]) t++; } if(t>=3) { for(i=1; i<=pp[pos].cnt; i++) { tmp[i]=app[pp[pos].v[i]]; app[pp[pos].v[i]]=0; } a[cxx]=pos; dfs(pos+1,cxx+1,pp[pos].time); for(i=1; i<=pp[pos].cnt; i++) { app[pp[pos].v[i]]=tmp[i]; } } dfs(pos+1,cxx,pretime); } else return ;}int main(){ int i,j,t,u,sz; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&w); for(i=1; i<=n; i++) { pp[i].id=i; scanf("%d%d",&pp[i].cnt,&pp[i].time); for(j=1; j<=pp[i].cnt; j++) { scanf("%d",&pp[i].v[j]); } } sort(pp+1,pp+n+1,cmp); ans=0; memset(app,1,sizeof(app)); for(i=1; i<=n; i++) { a[1]=i; for(j=1; j<=pp[i].cnt; j++) { app[pp[i].v[j]]=0; } dfs(i+1,2,pp[i].time); for(j=1; j<=pp[i].cnt; j++) { app[pp[i].v[j]]=1; } } sort(ansa+1,ansa+ans+1); printf("%d\n",ans); for(i=1; i

 

转载地址:http://ymkla.baihongyu.com/

你可能感兴趣的文章
Linux学习-环境变量
查看>>
java并发编程实战------阅读笔记第七章 取消与关闭
查看>>
原地打印刷新(倒计时)
查看>>
恶补C++ 之 类型转换
查看>>
LVM的学习资料
查看>>
SSH框架与MVC架构之间的关系
查看>>
配置Jenkins用户和权限
查看>>
Virtualbox虚拟机加入USB设备
查看>>
苏打绿 当我们一起走过 2012台北小巨蛋演唱会[1080P/720P/540P]
查看>>
两种交换机配置模式,以配置基于端口划分的VLAN为例
查看>>
Tomcat基础配置(2)-Tomcat连接器
查看>>
如何使用mysql命令在命令提示符下
查看>>
OpenGL(试用篇)——第一个OpenGL程序(1)
查看>>
用Maven部署war包到远程Tomcat服务器
查看>>
延时操作
查看>>
yum 时候出现Another app is currently holding the yum lock解决方法
查看>>
CyanogenMod 7 RC2,24小时下载量超 15 万
查看>>
给初级程序员的一封信
查看>>
文本编辑工具vim的使用方法
查看>>
一个很流行的版本控制系统Git学习笔记
查看>>