Gone Fishing
代码已经写出来了,自己测试的时候没有问题,提交上去之后反馈了我一个Runtime error 一口老血啊!
找了半天还是没找到可能越界啊啥的地方
import java.util.Scanner;
import java.util.Arrays;
import java.util.Queue;
import java.util.LinkedList;
//import java.math.*;
//import java.util.Arrays;
public class Main {
public static void main(String[] args){
Queue<Question> question=new LinkedList<Question>();
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
while(n!=0){
int h=sc.nextInt();
int fi[]=new int[n];
int di[]=new int[n];
int ti[]=new int[n-1];
for(int i=0;i<n;i++) fi[i]=sc.nextInt();
for(int i=0;i<n;i++) di[i]=sc.nextInt();
for(int i=0;i<n-1;i++)ti[i]=sc.nextInt()*5;
Question qu=new Question(n,h,fi,di,ti);
question.add(qu);
n=sc.nextInt();
}
sc.close();
while(!question.isEmpty()){
Question next=question.remove();
next.doSomething();
if(next.answer!=null)
System.out.print(next.answer[0]*5);
for(int i=1;i<next.answer.length;i++)
System.out.print(", "+next.answer[i]*5);
//for(int i:next.answer)
//System.out.print(i*5+",");
System.out.println("\nNumber of fish expected: "+next.number+"\n");
//System.out.println(next.ti[next.ti.length-1]);
}
}
}
class Question{
int n;
int h;
int[] fi;
int[] di;
int[] ti;
int[] answer;
int number;//用于保存最多可以钓多少鱼
private int temp;
Question(int a,int b,int[] c,int[] d,int [] e){
n=a;h=b;fi=Arrays.copyOf(c,c.length);di=Arrays.copyOf(d, d.length);ti=Arrays.copyOf(e, e.length);
}
public void doSomething(){
int max=0;int[] temp0 = null;
for(int i=1;i<=n;i++){
int x=h*60;
for(int j=0;j<i-1;j++) x-=ti[j];
int[] temp1=getBest(i,x,Arrays.copyOf(fi, i),Arrays.copyOf(di, i));
if(temp>max){
max=temp;
temp0=temp1;
}
}
number=max;
answer=temp0;
}
private int[] getBest(int n,int h,int[] fi,int[] di){
temp=0;int[] list=new int[this.n];
for(int i=0;i<h;i+=5){
int max=0;int flag=0;
for(int j=0;j<n;j++){
if(max<fi[j]){
flag=j;max=fi[j];
}
}
temp+=fi[flag];
list[flag]++;
//h-=5;
fi[flag]=fi[flag]>di[flag]?fi[flag]-di[flag]:0;
} return list;
}
}
Gone Fishing的更多相关文章
- ZOJ 1015 Fishing Net(弦图判定)
In a highly modernized fishing village, inhabitants there make a living on fishery. Their major tool ...
- bzoj 1242: Zju1015 Fishing Net 弦图判定
1242: Zju1015 Fishing Net弦图判定 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 214 Solved: 81[Submit ...
- Poj/OpenJudge 1042 Gone Fishing
1.链接地址: http://bailian.openjudge.cn/practice/1042/ http://poj.org/problem?id=1042 2.题目: Gone Fishing ...
- POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)
Gone Fishing Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 30281 Accepted: 9124 Des ...
- uva757 - Gone Fishing(馋)
题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...
- ●BZOJ 1006 [HNOI2008]神奇的国度(弦图最小染色数)○ZOJ 1015 Fishing Net
●赘述题目 给出一张弦图,求其最小染色数. ●题解 网上的唯一“文献”:<弦图与区间图>(cdq),可以学习学习.(有的看不懂) 摘录几个解决改题所需的知识点: ●子图和诱导子图(一定要弄 ...
- Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent
Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱 ...
- CSU 1859 Gone Fishing(贪心)
Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...
- Gone Fishing(贪心)
Gone Fishing John is going on a fising trip. He has h hours available (1 ≤ h ≤ 16), and there are n ...
- LightOJ1106 Gone Fishing
Gone Fishing John is going on a fishing trip. He has h hours available, and there are n lakes in the ...
随机推荐
- 浏览器默认标签样式总结及css初始化程序(转)
浏览器默认标签样式总结及css初始化程序 html中的大部分的标签都有一些糟糕的样式,有的是标签天然自带的,有的是浏览器默认设置的,我们在写网页时,这些默认的样式就会时不时的跳出来捣一下乱,搞得我 ...
- 线段树教做人系列(3) HDU 4913
题意及思路看这篇博客就行了,讲得很详细. 下面是我自己的理解: 如果只有2,没有3的话,做法就很简单了,只需要对数组排个序,然后从小到大枚举最大的那个数.那么它对答案的贡献为(假设这个数排序后的位置是 ...
- POJ 3580 SuperMemo (FHQ_Treap)
题意:让你维护一个序列,支持以下6种操作: ADD x y d: 第x个数到第y个数加d . REVERSE x y : 将区间[x,y]中的数翻转 . REVOLVE x y t :将区间[x,y] ...
- VMware内部错误解决办法
虚拟机内部错误,不要担心不是致命错误,往往是由于你的配置被禁用了或者VMware运行权限不够导致 检查你的VMware虚拟网卡是否被禁用 检查你的VMware的运行权限,直接管理员运行就够够的了
- 关于Lucene,你至少要知道的事
1.是什么? 全文搜索引擎 2.干什么? 实现网站全文检索功能(自带语法高亮功能) 3.原理? Lucene生成索引(语法解析后,生成索引文件)-根据索引进行查询(语法解析后,根据解析后的结果进行查询 ...
- java.io.FileNotFoundException: res/drawable/title_bar_shadow.9.png
ERROR/AndroidRuntime(803): Caused by: java.io.FileNotFoundException: res/drawable/title_bar_shadow.9 ...
- c语言判断是否是utf8字符串,计算字符个数
#include <stdio.h> #include <string.h> #include <stdlib.h> /********************** ...
- hadoop学习记录--hdfs文件上传过程源码解析
本节并不大算为大家讲接什么是hadoop,或者hadoop的基础知识因为这些知识在网上有很多详细的介绍,在这里想说的是关于hdfs的相关内容.或许大家都知道hdfs是hadoop底层存储模块,专门用于 ...
- 基于ef core 2.0的数据库增删改审计系统
1.首先是建审计存储表 CREATE TABLE [dbo].[Audit] ( [Id] [uniqueidentifier] NOT NULL, [EntityName] [nvarchar](1 ...
- AppDelegate生命周期回调顺序
1. 应用初次启动: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDiction ...