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 ...
随机推荐
- C++——override
override关键字作用: 如果派生类在虚函数声明时使用了override描述符,那么该函数必须重载其基类中的同名函数,否则代码将无法通过编译.举例子说明 struct Base { virtual ...
- Mongo client - cross-platform MongoDB management tool
Mongo client for Ubuntu or Windows http://robomongo.org/download.html
- linux文件夹删除、创建
一.删除文件夹 rm -rf ./html2imag 二.创建文件夹 mkdir html2image
- Unobrusive Ajax使用
mark一下:[ASP.NET MVC 小牛之路]14 - Unobtrusive Ajax篇文章,果断记下来,网址: http://www.cnblogs.com/willick/p/3418517 ...
- bat 操作数据库(附加,分离,删除,还原)
BAT代码: @echo off Title DataBase Color 0A :caozuo echo. echo ═══════════════════════════════════════ ...
- 与HDFS交互- By java API编程
环境(ubuntu下) jdk eclipse jar(很烦,整了很久才清楚) - 导包方法 查看:https://www.cnblogs.com/floakss/p/9739030.html ()” ...
- 转载 MySQL创建表的语句 示例
show variables like 'character_set_client';#查询字符集 show databases;#列出所有的服务器上的数据库alter create database ...
- 魔法少女 LJJ——线段树
题目 [题目描述] 在森林中见过会动的树,在沙漠中见过会动的仙人掌过后,魔法少女 LJJ 已经觉得自己见过世界上的所有稀奇古怪的事情了. LJJ 感叹道“这里真是个迷人的绿色世界,空气清新.淡雅,到处 ...
- 洛谷P2526 [SHOI2001]小狗散步(二分图匹配)
题目背景 Grant喜欢带着他的小狗Pandog散步.Grant以一定的速度沿着固定路线走,该路线可能自交.Pandog喜欢游览沿途的景点,不过会在给定的N个点和主人相遇.小狗和主人同时从(X1,Y1 ...
- js中 关于DOM的事件操作
一.JavaScript的组成 JavaScript基础分为三个部分: ECMAScript:JavaScript的语法标准.包括变量.表达式.运算符.函数.if语句.for语句等. DOM:文档对象 ...