54(2023.12.27)(数码,最大乘积,帮派)

54(2023.12.27)(数码,最大乘积,帮派)_第1张图片

#include
using namespace std;
#include
int arr[100001] = {};
struct zu
{
	int m_Num1;
	int m_Num2;
};
int main()
{
	int num1, num2;
	int k;
	cin >> k;
	vectorv;
	zu z;
	int flag;
	int times;
	for (int i = 0;i < k;i++)
	{
		cin >> num1 >> num2;
		z.m_Num1 = num1;
		z.m_Num2 = num2;
		v.push_back(z);
	}
	for (vector::iterator it = v.begin();it != v.end();it++)
	{
		for (int i = 0;i < 100001;i++)
		{
			arr[i] = 0;
		}
		arr[100000] = 1;
		for (int i = (*it).m_Num1;i >= 1;i--)
		{
			for (int j = 100000;j >= 0;j--)
			{
				arr[j] *= i;
			}
			for (int j = 100000;j >= 1;j--)
			{
				if (arr[j] >= 10)
				{
					arr[j - 1] += (arr[j] / 10);
					arr[j] %= 10;
				}
			}
		}
		flag = 0;
		times = 0;
		while (arr[flag] == 0)
		{
			flag++;
		}
		for (int j = 100000;j >= flag;j--)
		{
			if (arr[j] == (*it).m_Num2)
			{
				times++;
			}
		}
		cout << times++ << endl;
	}
	system("pause");
	return 0;
}

54(2023.12.27)(数码,最大乘积,帮派)_第2张图片 

#include
using namespace std;
#include
int arr[100001] = {};
int main()
{
	int n;
	cin >> n;
	int start = 2;
	int sum = 0;
	multisetmu;
	while (sum < n)
	{
		sum += start;
		if (sum <= n)
		{
			mu.insert(start);
			start++;
		}
		else if (sum > n)
		{
			int flag = sum - n;
			if (flag == 1)
			{
				mu.erase(2);
				start++;
				mu.insert(start);
				break;
			}
			else
			{
				mu.erase(flag);
				mu.insert(start);
				break;
			}
		}
	}
	arr[100000] = 1;
	for (multiset::iterator it = mu.begin();it != mu.end();it++)
	{
		cout << *it << " ";
		for (int i = 100000;i >= 0;i--)
		{
			arr[i] *= (*it);
		}
		for (int i = 100000;i >= 1;i--)
		{
			if (arr[i] >= 10)
			{
				arr[i - 1] += (arr[i] / 10);
				arr[i] %= 10;
			}
		}
	}
	int flag = 0;
	while (arr[flag] == 0)
	{
		flag++;
	}
	cout << endl;
	for (int i = flag;i < 100001;i++)
	{
		cout << arr[i];
	}
	cout << endl;
	system("pause");
	return 0;
}

54(2023.12.27)(数码,最大乘积,帮派)_第3张图片 

#include
using namespace std;
#include
#include
#include

struct people
{
	string m_Name;
	string m_Carrer;
	int m_Bangong;
	int m_Dgree;
};
bool mycompareByDgree(const people& peo1, const people& peo2)
{
	return peo1.m_Dgree > peo2.m_Dgree;
}
bool mycompareByDgree2(const people& peo1, const people& peo2)
{
	if (peo1.m_Dgree == peo2.m_Dgree)
	{
		return peo1.m_Bangong > peo2.m_Bangong;
	}
	return peo1.m_Dgree > peo2.m_Dgree;
}
bool mycompareByBangong(const people& peo1, const people& peo2)
{
	return peo1.m_Bangong > peo2.m_Bangong;
}
int main()
{
	int n;
	cin >> n;
	people p1;
	vectorv_result;
	string name, carrer;
	int bangong, dgree;
	cin >> name >> carrer;
	cin >> bangong >> dgree;
	p1.m_Bangong = bangong;
	p1.m_Carrer = carrer;
	p1.m_Dgree = dgree;
	p1.m_Name = name;
	v_result.push_back(p1);
	vectorv1;
	for (int i = 0;i < 2;i++)
	{
		cin >> name >> carrer;
		cin >> bangong >> dgree;
		p1.m_Bangong = bangong;
		p1.m_Carrer = carrer;
		p1.m_Dgree = dgree;
		p1.m_Name = name;
		v1.push_back(p1);
	}
	sort(v1.begin(), v1.end(),mycompareByDgree);
	for (vector::iterator it = v1.begin();it != v1.end();it++)
	{
		v_result.push_back(*it);
	}
	vectorv2;
	for (int i = 0;i < n-3;i++)
	{
		cin >> name >> carrer;
		cin >> bangong >> dgree;
		p1.m_Bangong = bangong;
		p1.m_Carrer = carrer;
		p1.m_Dgree = dgree;
		p1.m_Name = name;
		v2.push_back(p1);
	}
	sort(v2.begin(), v2.end(), mycompareByBangong);
	vector::iterator pos = v2.begin();
	vectorHuFa;
	vectorZhangLao;
	vectorTangZhu;
	vectorJingYing;
	vectorBangZhong;
	//for (vector::iterator it = v2.begin();it != v2.end();it++)
	for (int i = 0;i < n - 3;i++)
	{
		if (i < 2)
		{
			(*pos).m_Carrer = "HuFa";
			HuFa.push_back(*pos);
		}
		else if(i<6)
		{
			(*pos).m_Carrer = "ZhangLao";
			ZhangLao.push_back(*pos);
		}
		else if (i < 13)
		{
			(*pos).m_Carrer = "TangZhu";
			TangZhu.push_back(*pos);
		}
		else if (i < (13 + 25))
		{
			(*pos).m_Carrer = "JingYing";
			JingYing.push_back(*pos);
		}
		else
		{
			(*pos).m_Carrer = "BangZhong";
			BangZhong.push_back(*pos);
		}
		pos++;
	}
	sort(HuFa.begin(), HuFa.end(), mycompareByDgree2);
	sort(ZhangLao.begin(), ZhangLao.end(), mycompareByDgree2);
	sort(TangZhu.begin(), TangZhu.end(), mycompareByDgree2);
	sort(JingYing.begin(), JingYing.end(), mycompareByDgree2);
	sort(BangZhong.begin(), BangZhong.end(), mycompareByDgree2);
	for (vector::iterator it = HuFa.begin();it != HuFa.end();it++)
	{
		v_result.push_back(*it);
	}
	for (vector::iterator it = ZhangLao.begin();it != ZhangLao.end();it++)
	{
		v_result.push_back(*it);
	}
	for (vector::iterator it = TangZhu.begin();it != TangZhu.end();it++)
	{
		v_result.push_back(*it);
	}
	for (vector::iterator it = JingYing.begin();it != JingYing.end();it++)
	{
		v_result.push_back(*it);
	}
	for (vector::iterator it = BangZhong.begin();it != BangZhong.end();it++)
	{
		v_result.push_back(*it);
	}
	for (vector::iterator it = v_result.begin();it != v_result.end();it++)
	{
		cout << (*it).m_Name << " " << (*it).m_Carrer << " " << (*it).m_Dgree << endl;
	}
	system("pause");
	return 0;
}

 

 

你可能感兴趣的:(算法,数据结构)