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 ...
随机推荐
- ngx-bootstrap使用04 carousel组件
1 carousel 是一个通过循环播放图片.文本的幻灯片:就像一个旋转旋转木马一样,但是不支持嵌套使用 2 如何使用 2.1 搭建ngx-bootstrap使用环境 参见博文:点击前往 2.2 在模 ...
- ubuntu16.04.2安装tftp服务器
1.安装 $ apt-get install tftp-hpa tftpd-hpa tftp-hpa是客户端 tftpd-hpa是服务器 2.创建目录 $ mkdir /tftpboot 这是创建tf ...
- 关于集合的小demo
/*1.分析以下需求,并用代码实现: (1)有如下代码: (2)定义方法统计集合中指定元素出现的次数,如"e" 3,"f" 2,"g" 4* ...
- [译]Javasctipt中的substring
本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...
- delphi xe6 调用java GPS的方法
如果用xe6自带的LocationSensor控件,默认优先使用网络位置,网络位置定位精度不准确,不能满足高精度定位的要求.但xe6自带的LocationSensor控件不能指定网络定位优先还是GPS ...
- jquery ajax 分页2
/* * 分页 $("#divPager").flexipager * 2015.03.17 */ //初始化列表默认属性 (function($) { $.addFlex = f ...
- ipa包使用命令上传fir.im或者蒲公英
我们的工程做了自动打包处理,但是每次打完ipa后只是放置于一个共享盘或者本地,为了方便测试,每次都要手动上传上传fir或者蒲公英,比较麻烦.所以研究了一下怎么能在打完包后直接脚本上传到上传fir或者蒲 ...
- 重新排序文本文件(txt)里面的内容
近段时间,Insus.NET学习练习物件与对象,怎样创建实际环境中的对象.对读取文本文件以及分析文本文件作为目标.因此搜索论坛一些例子,就如下面这题,实现的方法分享给大家. 以文本行作为一个对象,所以 ...
- Django之博客系统邮件分享博客
在上一章中,我们创建了一个基础的博客应用,我们能在http://127.0.0.1:8000/blog/显示我们的博客.在这一章我们将尝试给博客系统添加一些高级的特性,比如通过email来分享帖子,添 ...
- WC2019 冬眠记
Day1 做高铁来广州 晚上开幕式,亮点在CCF的日常讲话.dzd有事换wh讲. 我们WC比赛的人数是最多的,性价比是最高的 然后掌声雷动 相信大家鼓掌是同意我的话 再次掌声雷动(雾 Day2-Day ...