资源简介
贪婪算法的实例,有问题陈述和具体的程序

代码片段和文件信息
#include “iostream.h“
#include “math.h“
#include “stdio.h“
#include “string“
#include “algorithm“
using namespace std;
int main()//整数接力问题
{
// freopen(“input.txt“ “r“ stdin);
//freopen(“output.txt“ “w“ stdout);
///////////////////////////////////////读入数据
int ijmark_maxmark_min;
int lo;
int n;
while(scanf(“%d“&n)!=EOF){
char **num=new char* [n];
bool *A=new bool [n];//判断是否已经输出了0表示未输出
for (i=0;i A[i]=0;
num[i]=new char[11];//二维字符数组,保存读入的数字,把数字当成字符处理
scanf(“%s“num[i]);
}
/////////////////////////////////////////数据预处理找最小的数
char *min*max;
min=num[0];
mark_min=0;
for(i=1;i for (j=0l=0;j<11&&l<11;){
if (min[j]>num[i][l]){
min=num[i];
mark_min=i;
break;
}
else if(min[j]==num[i][l]){//产生前缀码时的情况
if (min[j+1]==‘\0‘&&num[i][l+1]==‘\0‘)//应从非前缀移动前缀码的长度后再比较
break;
else if(min[j+1]!=‘\0‘&&num[i][l+1]!=‘\0‘){
l++;j++;
}
else if(min[j+1]!=‘\0‘&&num[i][l+1]==‘\0‘){
l=0;j++;
}
else if (num[i][l+1]!=‘\0‘&&min[j+1]==‘\0‘){
j=0;l++;
}
}
else break;
}
}
//////////////////////////////////
for(o=0;o max=min;//以最小的数为基准,每次找出最大的数,并输出
mark_max=mark_min;
for (i=0;i if(A[i]==0){
for (j=0l=0;j<11&&l<11;){
if(max[j] max=num[i];
mark_max=i;
break;
}
else if(max[j]==num[i][l]){//产生前缀码时的情况
if (max[j+1]==‘\0‘&&num[i][l+1]==‘\0‘){
if (mark_min==i)//最小数为i时直接跳出两个数字的比较
break;
else{
max=num[i];
mark_max=i;
break;
}
}
else if(max[j+1]!=‘\0‘&&num[i][l+1]!=‘\0‘){
l++;j++;continue;
}
else if(max[j+1]!=‘\0‘&&num[i][l+1]==‘\0‘){//应从非前缀移动前缀码的长度后再比较
l=0;j++;
continue;
}
else if (num[i][l+1]!=‘\0‘&&max[j+1]==‘\0‘){
j=0;l++;
continue;
}
}
else break;
}
}
}
if(A[mark_max]==0){
printf(“%s“max);
A[mark_max]=1;
}
}
printf(“\n“);
for(i=0;i delete []num[i];
}
delete []num;
}
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 64553 2008-11-07 19:35 conint整数接力问题\conint.pdf
文件 75264 2008-11-22 23:37 conint整数接力问题\conint54.ppt
文件 2337 2008-11-22 23:36 conint整数接力问题\conint54.txt
文件 2337 2010-04-25 11:20 conint整数接力问题\conints.cpp
文件 2337 2010-04-25 11:19 conint整数接力问题\conint陈颖(男).cpp
文件 3563 2010-04-25 11:28 conint整数接力问题\conint陈颖(男).dsp
文件 536 2010-04-25 11:28 conint整数接力问题\conint陈颖(男).dsw
文件 33792 2010-04-25 11:28 conint整数接力问题\conint陈颖(男).ncb
文件 48640 2010-04-25 11:28 conint整数接力问题\conint陈颖(男).opt
文件 784 2010-04-25 11:27 conint整数接力问题\conint陈颖(男).plg
文件 75776 2008-11-20 23:07 conint整数接力问题\conint陈颖(男).ppt
文件 10397 2010-04-25 11:27 conint整数接力问题\Debug\conints.obj
文件 10573 2010-04-25 11:20 conint整数接力问题\Debug\conint陈颖(男).obj
文件 2743268 2010-04-25 11:20 conint整数接力问题\Debug\conint陈颖(男).pch
文件 91136 2010-04-25 11:27 conint整数接力问题\Debug\vc60.idb
文件 110592 2010-04-25 11:20 conint整数接力问题\Debug\vc60.pdb
目录 0 2010-07-11 19:04 conint整数接力问题\Debug
目录 0 2010-07-11 19:04 conint整数接力问题
----------- --------- ---------- ----- ----
3275885 18
- 上一篇:校园局域网设计要求
- 下一篇:剑侠情缘3网络版全套源代码
相关资源
- 遗传算法PPT(Genetic_Algorithms.ppt)
- A discrete fruit fly optimization algorithm fo
- A Novel Algorithm for Ternary Reversible Logic
- 算法导论introduction to algorithms 课后习
- Introduction to Algorithms - A Creative Approa
- Digital signal processing principlesalgorithms
- 算法导论(第2版)Introduction to Algor
- Introduction to Algorithms第三版中文版
- Graph Algorithms:Practical Examples in Apach
- memetic 算法论文
- Data Structures and Algorithm Analysis in C 2n
- Algorithms3rdEdition.zip
- Algorithms for reinforcement learning
- Bioinformatics Algorithms: an Active Learning
- 算法导论英文版Introduction to Algorithm
- master_machine_learning_algorithms285570
- Data clustering algorithm and application
- Quantitative Trading - How to Build Your Own A
- 算法和数据结构:基本工具箱Kurt Me
- 高清彩版 Distributed.Systems.An.Algorithmi
- r for mcmc
-
em
bedded Deep Learning_ Algorithms Architec - Planning Algorithms pdf书
- [mobi资源+pdf] Network Algorithmics
- Machine Learning_Algorithms and Applications (
- Numerical Algorithms Methods for Computer Visi
- Algorithmic Trading Winning Strategies and The
- Pearls of Functional algorithm design
- Introduction to Algorithms
- Learning Algorithms Through Programming and Pu
评论
共有 条评论