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 ...
随机推荐
- Ros学习——值得学习的package
RViz是一款强大的可视化工具,它允许你查看机器人中的传感器和内部状态. TF程序包(package)提供在机器人所使用到的各种坐标系之间的变换功能,并保持跟踪这些变换的变化. actionlib - ...
- Excel课程学习
1.Excel软件简介 1.1历史上的其他数据处理软件与Microsoft Excel 1977年,苹果公司开发了一款数据处理软件,当时这款软件卖的非常好,用软件的尾巴摇动硬件的狗,当时有人因为这款软 ...
- HTML5应用程序缓存Application Cache.RP
什么是Application Cache HTML5引入了应用程序缓存技术,意味着web应用可进行缓存,并在没有网络的情况下使用,通过创建cache manifest文件,可以轻松的创建离线应用. A ...
- SDUT 3376 数据结构实验之查找四:二分查找
数据结构实验之查找四:二分查找 Time Limit: 20MS Memory Limit: 65536KB Submit Statistic Problem Description 在一个给定的无重 ...
- HDU 5033 Building (维护单调栈)
题目链接 题意:n个建筑物,Q条询问,问所在的位置,看到天空的角度是多少,每条询问的位置左右必定是有建筑物的. 思路 : 维护一个单调栈,将所有的建筑物和所有的人都放到一起开始算就行,每加入一个人,就 ...
- java反射机制的进一步理解
承上一篇. JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法:这种动态获取的信息以及动态调用对象的方法的功能称为java语 ...
- iframe加载的文档高度
var clientHeight = $("#iframe").contents().find("body").height();
- Metasploit 读书笔记-持久控制
Meterpreter的persisitence脚本允许主任meterpreter代理,以确保系统重启之后Meterpreter还能运行。如果是反弹连接方式,可以设置连接攻击机的时间间隔。如果是绑定方 ...
- boostrap selectpicker 用法
1..html中先引用 <link href="{{ url_for('static', filename='css/bootstrap-select.css') }}" r ...
- day06.2-软链接与硬链接
1. 建立软链接:ln -s 源文件 链接文件 特点:a). 相当于Windons系统中的快捷方式: b). 删除链接文件不影响源文件内容,而删除源文件后链接文件随即失效: ...