• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ACM s1124yy
守りたいものが 強くさせること
博客园    首页    新随笔    联系   管理     

CSU 1859 Gone Fishing(贪心)

Gone Fishing

【题目链接】Gone Fishing

【题目类型】贪心

&题解:

这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = =
之后在枚举每个湖的鱼的个数,之后总是选最大的就好了,这里我是直接变的f数组,所以最后一定不要忘了在赋值回来

【时间复杂度】\(O(n^2k)\)

&代码:

#include <cstdio>
#include <bitset>
#include <iostream>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
const int maxn= 30 +9;
int n,h,f[maxn],K,ff[maxn],d[maxn],t[maxn];
vector<int> v1,v2;
int main()
{
//	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	freopen("E:1.txt","r",stdin);
	while(cin>>n){
		if(K!=0) cout<<endl; K++;
		if(n==0)break;
		cin>>h; h*=12;
		for(int i=0;i<n;i++) cin>>f[i],ff[i]=f[i];
		for(int i=0;i<n;i++) cin>>d[i];
		for(int i=1;i<n;i++) {cin>>t[i];t[i]+=t[i-1];}
		int ans=0;
		for(int i=0;i<n;i++) {
			v2.clear(); v2.resize(n);
			int tm=h-t[i];
//			cout<<"tm="<<tm<<endl;
			if(tm<0) break;
			int a1=0;
			for(int i=0;i<n;i++) f[i]=ff[i];
			for(int o=0;o<tm;o++){
				int ma=0,ps=0;
				for(int j=0;j<=i;j++){
					if(ma<f[j]){
						ma=f[j];
						ps=j;
					}
				}
//				if(tm==10){
//					cout<<"ps="<<ps<<" f[ps]="<<f[ps]<<endl;
//				}
				a1+=f[ps];
				v2[ps]++;
				f[ps]-=d[ps];
				if(f[ps]<0) f[ps]=0;
			}
			if(ans<a1){
				v1=v2;
				ans=a1;
			}
		}
		for(int i=0;i<n;i++){
			cout<<v1[i]*5;
			if(i!=n-1)cout<<", ";
		}cout<<endl;
		cout<<"Number of fish expected: "<<ans<<endl;
	}
	return 0;
}
posted @ 2017-04-04 01:21  s1124yy  阅读(190)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3