当前位置: 首页>>代码示例>>C++>>正文


C++ BinaryHeap::increase_by_iD方法代码示例

本文整理汇总了C++中BinaryHeap::increase_by_iD方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryHeap::increase_by_iD方法的具体用法?C++ BinaryHeap::increase_by_iD怎么用?C++ BinaryHeap::increase_by_iD使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryHeap的用法示例。


在下文中一共展示了BinaryHeap::increase_by_iD方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[] )
{	

	srand (time(NULL));

	clock_t start;

	double seconds_since_start;

        BinaryHeap<soldier> heap;
	
	soldier nextUp;

	vector<int> alive_Spartans, alive_Persians;

	

	int total_Spartans, total_Persians, increase_Amount, time_Elapsed = 0, spartan_Count = 0, persian_Count = 0;
	int numberOfSpartanVictories = 0, numberOfPersianVictories = 0;

	double sum_Spartans = 0, sum_Persians = 0, sum_Time = 0, spartan_Squared= 0, persian_Squared = 0, time_Squared = 0; 
	double spartan_Final_Average = 0, persian_Final_Average = 0, time_Final_Average = 0, omega_Spartan = 0, omega_Time = 0;
	long double omega_Persian = 0;

	vector<double> soldier_count_Spartans, soldier_count_Persians, time_Count;

	total_Spartans = atoi(argv[2]);
	total_Persians = atoi(argv[3]);
	
	spartan_Count = total_Spartans;
	persian_Count = total_Persians;

	int numberOfTimes;
	numberOfTimes = atoi(argv[1]);

	cout << "You have set the simulations to run for: " << numberOfTimes << " times." << endl;
	cout << "You have selected the number of spartans to be: " << spartan_Count << endl;
	cout << "You have selected the number of persians to be: " << persian_Count << endl;

	if(total_Spartans == 0 || total_Persians == 0){
		cout << "what are you doing" << endl;
		exit(1);
	}

	string outputFile;
	cout << "Enter the name of the file to output results to: " << endl;
	cin >> outputFile;

	ofstream file(outputFile);
	
	
	//cout << "How many times would you like to simulate the battle?" << endl;
	

	//char begin;

	cout << "You have set the simulations to run for: " << numberOfTimes << " times." << endl;
	cout << "You have selected the number of spartans to be: " << spartan_Count << endl;
	cout << "You have selected the number of persians to be: " << persian_Count << endl;
	//cout << "Enter any character to proceed..." << endl;
	//cin >> numberOfTimes;
	
	for(int i = 0; i < numberOfTimes; i++)
	{
		start = clock();
		generate_Soldiers(heap, total_Spartans, total_Persians, alive_Spartans, alive_Persians);

		//invigorate(heap, alive_Spartans, total_Spartans);


		//cout << "The ID's of all our Spartans: " << endl;
		//printOutIDs(alive_Spartans, total_Spartans);
		//cout << "The ID's of all our Persians: " << endl;
		//printOutIDs(alive_Persians, total_Persians);
	
		cout << "Our heap reports these soldiers: " << endl;
		//heap.printAllSoldiers();
		cout << "------------------------Let the battle begin!-------------------------" << endl;
		while( spartan_Count > 0 && persian_Count > 0)
		{
			//cout << "Spartans left: " << spartan_Count << endl;
			//cout << "Persians left: " << persian_Count << endl;

			nextUp = heap.findMin();//Peek at the first soldier. This is the soldier whose turn is next

			time_Elapsed = nextUp.return_actionTime();
			//cout << "Next up: " << "soldier number: " << nextUp.return_iD() << endl;
			//cout << "This soldier's turn is at: " << nextUp.return_actionTime() << endl;
			//if(nextUp.return_Faction() == true) //cout << "A Spartan! " << endl;
			//else //cout << "A Persian!" << endl;
			if(nextUp.return_Faction()  == true) processTurn(heap, alive_Persians, persian_Count);
			else processTurn(heap, alive_Spartans, spartan_Count);

			//The soldier's key is edited; his next turn is determined by adding a random value to his turn time atm.
			if(nextUp.return_Faction() == true) heap.increase_by_iD(nextUp.return_iD(), rand() % 7 + 1);
			else if(nextUp.return_Faction() == false) heap.increase_by_iD(nextUp.return_iD(), rand() % 51 + 10);

			//cout << "After the event, our heap looks like: " << endl;
			//cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
			//heap.printAllSoldiers();
//.........这里部分代码省略.........
开发者ID:jseuribe,项目名称:335_project3,代码行数:101,代码来源:sim300.cpp


注:本文中的BinaryHeap::increase_by_iD方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。