寒假6-洛谷打题

寒假6-洛谷打题_第1张图片

#include
using namespace std;

int arr_A[100010];
int arr_B[100010];
int arr_X[100010];
int arr_Y[100010];

int main()
{
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		cin >> arr_A[i] >> arr_B[i] >> arr_X[i] >> arr_Y[i];
	}
	int x, y;
	cin >> x >> y;
	int flag = -1;
	for (int i = n;i >= 1;i--)
	{
		if (x >= arr_A[i] && y >= arr_B[i] && x <= arr_A[i] + arr_X[i] && y <= arr_B[i] + arr_Y[i])
		{
			flag = i;
		}
		if (flag != -1)break;
	}
	cout << flag << endl;
	return 0;
}

 寒假6-洛谷打题_第2张图片

#include
using namespace std;

int shang[25], xia[25], kai[25];
int main()
{
	int a, n, m, x;
	cin >> a >> n >> m >> x;
	for (int i = 1;i <= n;i++)
	{
		if (i == n)
		{
			kai[i] == 0;
		}
		else if (i == 1)
		{
			shang[i] = a;
			xia[i] = 0;
			kai[i] = a;
		}
		else if (i == 2)
		{
			shang[i] = a;
			xia[i] = a;
			kai[i] = a;
		}
		else
		{
			shang[i] = shang[i - 1] + shang[i - 2];
			xia[i] = shang[i - 1];
			kai[i] = kai[i - 1] + shang[i] - xia[i];
		}
		
	}
	cout << kai[x] << endl;
	return 0;
}

寒假6-洛谷打题_第3张图片

#include
using namespace std;
int main()
{
	int n;
	cin >> n;
	int num1, num2;
	int flag = 1;
	for (int i = 1;i <= n;i++)
	{
		if (i == 1)num1 = num2 = 1;
		else if (flag == 1)
		{
			num2++;
			flag = 2;
		}
		else if (flag == 2)
		{
			num1++;
			num2--;
			if (num2 == 1)flag = 3;
		}
		else if (flag == 3)
		{
			num1++;
			flag = 4;
		}
		else if (flag == 4)
		{
			num1--;
			num2++;
			if (num1 == 1)flag = 1;

		}
	}
	cout << num1 << "/" << num2 << endl;
	return 0;
}

 寒假6-洛谷打题_第4张图片

#include
using namespace std;
#include
int f(char ch)
{
	if (int(ch) <= 57)return int(ch) - 48;
	else return (int(ch) - 55);
}
int main()
{
	int x;
	string str;
	cin >> x >> str;
	int l = str.length();
	int start = 1;
	int sum = 0;
	for (int i = 1;i <= l;i++)
	{
		sum += start*(f(str[l - i]));
		start *= x;
	}

	cout << sum << endl;
	return 0;
}

 寒假6-洛谷打题_第5张图片

#include
using namespace std;
int start = 1;
char ch[3000];
void f(int x)
{
	if (x <= 9)ch[start] = char(x + 48);
	else ch[start]=char(x + 55);
	start++;
}
int main()
{
	int n, x;
	cin >> n >> x;
	while (n)
	{
		f(n % x);
		n /= x;
	}
	for (int i = start-1;i >= 1;i--)
	{
		cout << ch[i];
	}
	return 0;
}

寒假6-洛谷打题_第6张图片

寒假6-洛谷打题_第7张图片

#include
using namespace std;
int n, temp;
int arr[25];
bool f(int num1, int num2)
{
	int wei1 = 0, wei2 = 0;
	int n1 = num1, n2 = num2;
	while (n1)
	{
		wei1++;
		n1 /= 10;
	}
	while (n2)
	{
		wei2++;
		n2 /= 10;
	}
	if (wei1 == wei2)
	{
		if (num1 > num2)return true;
		else return false;
	}
	else if (wei1 > wei2)
	{
		n1 = num1, n2 = num2;
		for (int i = 1;i <= (wei1 - wei2);i++)
		{
			n2 *= 10;
		}
		if (n1 > n2)return true;
		else return false;
	}
	else
	{
		n1 = num1, n2 = num2;
		for (int i = 1;i <= (wei2 - wei1);i++)
		{
			n1 *= 10;
		}
		if (n1 > n2)return true;
		else return false;
	}
}
int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		cin >> arr[i];
	}
	for (int i = 1;i <= n;i++)
	{
		for (int j = 1;j <= n-1;j++)
		{
			if (f(arr[j+1], arr[j]))
			{
				int temp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = temp;
			}
		}
	}
	for (int i = 1;i <= n;i++)
	{
		cout << arr[i];
	}
	cout << endl;
	return 0;
}

寒假6-洛谷打题_第8张图片

#include
using namespace std;
#include
int n;
struct pintai
{
	int m_Num;
	int m_H;
	int m_Left;
	int m_Right;
};
pintai arr[1010];
int main()
{
	cin >> n;
	pintai p;
	for (int i = 1;i <= n;i++)
	{
		p.m_Num = i;
		cin >> p.m_H >> p.m_Left >> p.m_Right;
		arr[i] = p;
	}
	for (int i = 1;i <= n;i++)
	{
		int chaleft = 2000000, charight = 2000000;
		int ans1 = 0;
		int ans2 = 0;
		for (int j = 1;j <= n;j++)
		{
			if (j != i)
			{
				if (arr[i].m_H >= arr[j].m_H)
				{
					if (arr[i].m_Left > arr[j].m_Left && arr[i].m_Left < arr[j].m_Right)
					{
						if (arr[i].m_H - arr[j].m_H < chaleft)
						{
							chaleft = arr[i].m_H - arr[j].m_H;
							ans1 = arr[j].m_Num;
						}
					}

					if (arr[i].m_Right > arr[j].m_Left && arr[i].m_Right < arr[j].m_Right)
					{
						if (arr[i].m_H - arr[j].m_H < charight)
						{
							charight = arr[i].m_H - arr[j].m_H;
							ans2 = arr[j].m_Num;
						}
					}
				}
			}
		}
		cout << ans1 << " " << ans2 << endl;
	}
	return 0;
}

寒假6-洛谷打题_第9张图片 

 

#include
using namespace std;
int arr[55];
int main()
{
	long long n;
	cin >> n;
	long long sum = 0;
	for (int i = 1;i <= n;i++)
	{
		cin >> arr[i];
		sum += arr[i];
	}
	long long left, right;
	cin >> left >> right;
	int ans1 = 0, ans2 = 0;
	if (sumright * n)cout << -1 << endl;
	else
	{
		for (int i = 1;i <= n;i++)
		{
			if (arr[i] < left)ans1 += (left - arr[i]);
			else if (arr[i] > right)ans2 += (arr[i] - right);
		}
		int ans = max(ans1, ans2);
		cout << ans << endl;
	}
	return 0;
}

寒假6-洛谷打题_第10张图片 

#include
using namespace std;
int a[200010];
int s[200010];
int main()
{
	int n;
	cin >> n;
	int ans = -2700000;
	for (int i = 1;i <= n;i++)
	{
		cin >> a[i];
		if (i == 1)s[i] = a[i];
		else
		{
			s[i] = max(s[i - 1] + a[i], a[i]);
			
		}
		if (s[i] > ans)ans = s[i];
	}
	cout << ans;
	return 0;
}

寒假6-洛谷打题_第11张图片 

 

 寒假6-洛谷打题_第12张图片

#include
using namespace std;
#include
#include
#include
float n, t;
struct jb
{
	float weight;
	float value;
	float ave;
};
bool compare(jb j1, jb j2)
{
	return j1.ave > j2.ave;
}
int main()
{
	jb j;
	float ans = 0;
	cin >> n >> t;
	vectorv;
	for (int i = 1;i <= n;i++)
	{
		cin >> j.weight >> j.value;
		j.ave = j.value / j.weight;
		v.push_back(j);
	}
	sort(v.begin(), v.end(), compare);
	for (vector::iterator it = v.begin();it != v.end();it++)
	{
		if (t == 0)break;
		else if (t >= (*it).weight)
		{
			ans += (*it).value;
			t -= (*it).weight;
		}
		else if (t < (*it).weight)
		{
			ans += (*it).ave * t;
			t = 0;
		}
		
		if (t == 0)break;
	}
	printf("%.2f", ans);
	return 0;
}

寒假6-洛谷打题_第13张图片 

#include
using namespace std;
#include
#include
struct people
{
	int m_Num;
	int m_Time;
};
bool compare(people p1, people p2)
{
	return p1.m_Time < p2.m_Time;
}
int main()
{
	int n;
	cin >> n;
	if (n == 1)
	{
		cout << 1 << endl << 0 << endl;
		return 0;
	}
	people p;
	vectorv;
	for (int i = 1;i <= n;i++)
	{
		p.m_Num = i;
		cin >> p.m_Time;
		v.push_back(p);
	}
	sort(v.begin(), v.end(), compare);
	float flag = n-1;
	float ans = 0;
	for (vector::iterator it = v.begin();it != v.end();it++)
	{
		cout << (*it).m_Num << " ";
		ans += (flag * (*it).m_Time)/n;
		flag -= 1;
	}
	cout << endl;
	printf("%.2f", ans);
	return 0;
}

 

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