69,372
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<vector>
#define MAX 2
#include <limits>
using namespace std;
int n = 3;
const double dist[3][3]={0,1,2,
1,0,3,
2,3,0};
double shortestPath(vector<int>& path,vector<bool>& visited,double currentLength){
if(path.size() == n)
return currentLength + dist[path[0]][path.back()];
double ret = 500;
for(int next=0;next<n;next++){
if(visited[next])
continue;
int here = path.back();
path.push_back(next);
visited[next] = true;
double cand = shortestPath(path,visited,currentLength+dist[here][next]);
ret = min(ret,cand);
visited[next] = false;
path.pop_back();
}
return ret;
}
int main()
{
vector<int> path;
vector<bool> visited(3,false);
double currentLength = 0;
double a = shortestPath(path,visited,currentLength);
cout<<"最短距离为:"<<a<<endl;
return 0;
}
我的也有同样的问题#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(void)
{
int face, roll, frequency[6000] = { 0 };
srand(time(NULL));
for (roll = 1; roll <= 6000; roll++)
{
face = rand() % 6000; //防止数组下标越界
frequency[face] += 1;
}
for (face = 1; face <= 6; face++)
{
printf("%d %d\n", face, frequency[face]);
}
return 0;
}
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(void)
{
int face, roll, frequency[6000] = { 0 };
srand(time(NULL));
for (roll = 1; roll <= 6000; roll++)
{
face = rand() % 6000; //防止数组下标越界
frequency[face] += 1;
}
for (face = 1; face <= 6; face++)
{
printf("%d %d\n", face, frequency[face]);
}
return 0;
}
frequency[face]+=1;