poj1042
2013-07-01 15:56
447 查看
Gone Fishing
http://poj.org/problem?id=1042
此题枚举+贪心 解决,注意时间以5分钟为一个单位。
Memory: 244K Time: 125MS
源代码
http://poj.org/problem?id=1042
此题枚举+贪心 解决,注意时间以5分钟为一个单位。
Memory: 244K Time: 125MS
源代码
//优先排序 贪心算法 #include<iostream> using namespace std; #define NUM_LIMIT 26 int n; int f[NUM_LIMIT]; int d[NUM_LIMIT]; int t[NUM_LIMIT-1]; int max; int array_max[NUM_LIMIT]; //max stay time void input() { //cin>>h; for (int i = 1; i <= n; ++i){ //!!! ++i i++ the same! cin >> f[i]; } for (int i = 1; i <= n; ++i){ cin >> d[i]; } for (int i = 1; i < n; ++i){ cin >> t[i]; } } void most_til(int h, int n, int * arr) //h num of 5 mins { for(int i=0;i<NUM_LIMIT;i++) arr[i] = 0; } void calculate() { int array_temp[NUM_LIMIT]; //init max = -1; int h_count=h*60/5; t[0]=0; for (int i=1; i<=n; i++){ //stop at lake i h_count = h_count-t[i-1]; if(h_count <= 0){ if (max < 0){ max = 0; for (int j=1; j<=n; j++){ array_max[j]=0; } } break; } int temp = most_til(h_count, i, array_temp); //max=max>temp?max:temp; if (max < temp) { max = temp; copy(array_max, array_temp); //call by reference } } } void output() { for(int i=1; i<n; i++){ cout << array_max[i] << ", "; } cout << array_max << endl; cout << "Number of fish expected: " << max << endl << endl; } int main() { //int n; //cout<<n<<endl; while(cin>>n&&n!=0){ input(); calculate(); output(); } return 0; }
相关文章推荐
- 2632 Crashing Robots的解决方法
- 1573 Robot Motion (简单题)
- 状态压缩DP poj 2817 WordStack 入门题
- POJ 2801 填词游戏
- POJ1003解题方案
- POJ2418解题方案
- POJ 1003 java
- poj水题
- poj 1417 True Liars 解题报告 并查集 DP
- poj2243Knight Moves(Floyed-Warshall)
- poj3468(线段树成段更新)
- poj3264(RMQ问题的线段树实现方法)
- poj2777Count color(线段树)
- poj2823(线段树)
- poj1679(The Unique MST)Kruskal
- poj2352Stars(树状数组)
- poj1195(二维树状数组)
- poj2236(Wireless Network)
- poj1470(Closest Common Ancestors)
- poj2536二分图匹配