首页 > 其他分享 >UVA - 757 Gone Fishing 贪心+枚举

UVA - 757 Gone Fishing 贪心+枚举

时间:2023-04-07 11:09:02浏览次数:40  
标签:Gone 757 int scanf printf ++ l2 Fishing time


题目大意:有n个湖泊,每个湖泊最初的5分钟能钓到f条鱼,每五分钟减少d条鱼,鱼的数目不能小于d也不能为负数,求在h小时能钓到的鱼的最大数目和在每个池塘带了多少分钟

解题思路:一个个枚举,如果用总时间减去到达另一个湖泊的时间的话,就表示它可以在两个湖泊随意行走了,然后在这些时间找到优解,并和前几次的最优解进行比较,就能得到结果

#include<cstdio>
#include<cstring>
const int maxn = 30 + 5;
int n, h;
int r[maxn];
struct Lake{
	int f;
	int d;
	int t;
};
Lake l1[maxn],l2[maxn],out[maxn];

int main(){
	int b = 1;
	while(scanf("%d", &n) && n) {

		if(b) 
			b = 0;
		else
			printf("\n");

		scanf("%d", &h);
		h = h * 60;
		for(int i = 0; i < n; i++)  {
			scanf("%d", &l1[i].f);
			l1[i].t = 0;
		}
		for(int i = 0; i  < n; i++)
			scanf("%d", &l1[i].d);
		for(int i = 0; i < n - 1; i++)
			scanf("%d", &r[i]);

		int max = -0x3f3f3f3f;
		int count = 0;

		for(int i = 0 ; i < n; i++) {
			int sum = 0;
			int time = h;

			for(int j = 0; j < n; j++)  {
				l2[j] = l1[j];
			}

			for(int j = 0; j < i; j++)
				time = time - 5 * r[j];
			
			while(time > 0) {
				int m = -0x3f3f3f3f;
				int s;
				for(int j = 0; j <= i; j++)
					if(l2[j].f > m ) {
						m = l2[j].f;
						s = j;
					}
				sum = sum + l2[s].f;
				if(l2[s].f - l2[s].d >= 0)
					l2[s].f = l2[s].f - l2[s].d;
				else
					l2[s].f = 0;

				l2[s].t = l2[s].t + 5;
				time = time -5;
			}
			if(sum > max) {
				max = sum;
				for(int j = 0; j < n; j++)  
					out[j] = l2[j];	
				
			}
		}
		printf("%d",out[0].t);

		for(int i = 1 ; i < n; i++)
			printf(", %d",out[i].t);
		printf("\n");
		printf("Number of fish expected: %d\n",max);
	}
	return 0;
}






标签:Gone,757,int,scanf,printf,++,l2,Fishing,time
From: https://blog.51cto.com/u_10970600/6175561

相关文章

  • 1757. 可回收且低脂的产品
    题目链接:https://leetcode.cn/problems/recyclable-and-low-fat-products/题目描述: 由题目可知,我们需要查找低脂可回收的产品编号,用一行就可以搞定:SELECTproduct_i......
  • mysql报错:MySQL server has gone away
    一、报错提示:   二、报错原因:原因一:一种可能是发送的SQL语句太长,以致超过了max_allowed_packet的大小,如果是这种原因,你只要修改my.cnf,加大max_allowed_pac......
  • 756~757 Session 细节2,细节3销毁
    4.细节:1.当客户端关闭后,服务器不关闭,两次获取session是否为同一个默认情况下。不是2.客户端不关闭,服务器关闭后,两次获取的Session是同一个吗?不......
  • 鱼塘钓鱼(fishing)
    鱼塘钓鱼(fishing)时间限制:1000ms      内存限制:65536KB提交数:149   通过数:81 三种做法:纯贪心做法堆维护DP【题目描述】有N个鱼塘排成一排(N<100),每个......
  • NYOJ-757-期末考试
    期末考试时间限制:1000ms|内存限制:65535KB难度:2描述马上就要考试了,小T有许多作业要做,而且每个老师都给出来了作业要交的期限,如果在规定的期限内没交作业就会扣......
  • Android View VISIBLE,INVISIBLE和GONE的区别
    AndroidViewVISIBLE,INVISIBLE和GONE的区别首先整理一下View的三种显示的形式,VISIBLE,INVISIBLE和GONE。/***Thisviewisvisible.*Usewith{@link......
  • CF757G Can Bash Save the Day? (复健 Day 1)
    先差分为\(Q(r)-Q(l-1)\),\(Q(i)=\sum_{j=1}^{i}\operatorname{dis}(p_j,x)\)。树上在线路径优先考虑点分树,先想询问怎么做,我们记\(f_i\)为点分树上\(i\)点子树内所......
  • luogu P2757 [国家集训队]等差子序列
    Link题解降智了。。。首先我们不需要关心\(Len\)是多少,只需要找到长度为\(3\)的等差子序列就行了。然后就枚举中点\(mid\),看看存不存在\(l<mid<r\)使得\(a_{mi......
  • P1757 通天之分组背包
    P1757通天之分组背包有\(N\)件物品和一个容量为\(V\)的背包。第\(i\)件物品的费用是\(C_i\),价值是\(W_i\)。这些物品被划分为\(K\)组,每组中的物品互相冲突,最......
  • 数据库文件导入报错"MySQL server has gone away"
    今天mysql从一个mysql库中导入另一个mariadb库中是总是报:ERROR2006(HY000)atline176infile:'xxx.sql':MySQLserverhasgoneaway但我是在当前服务器上导入的......