啊?×n
查看原帖
啊?×n
1213524
C_plus_plus_12345楼主2024/11/25 22:49

代码

#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
#define LLlimit numeric_limits<long long>::max()
using namespace std;

bool CFDP(const vector<int>& a)
{
	for (size_t i = 0; i < a.size(); ++i)
	{
		for (size_t j = i + 1; j < a.size(); ++j)
		{
			if ((a[i] * a[j]) % 154 == 0 || (a[i] * a[j]) % 147 == 0)
			{
				return true;
			}
		}
	}
	return false;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin >> T;
	while(T--)
	{
		int n, k;
		cin >> n >> k;
		vector<int> a(n);
		vector<int> b(n);
	
		for (int i = 0; i < n; ++i)
		{
			cin >> a[i];
		}
	
		int operations = 0;
		long long sum = 0;
	
		for (int i = 0; i < n; ++i)
		{
			sum += a[i];
		}
	
		while (sum != k)
		{
			if (!CFDP(a))
			{
				break; // 如果没有找到符合条件的对,则跳出循环
			}
	
			// 如果找到符合条件的对,则翻倍所有元素
			for (int i = 0; i < n; ++i)
			{
				a[i] *= 2;
			}
	
			operations++;
			sum = 0;
			for (int i = 0; i < n; ++i)
			{
				sum += a[i];
			}
			b = a;
			sort(b.begin(), b.end());
			if (sum >= k || (LLlimit / 2 < *(b.end())))
			{
				// 如果总和超过k或存在溢出风险,则跳出循环
				break;
			}
		}
	
		if (sum >= k)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}

	return 0;
}

结果给我蹦了个 2020 分出来(六个超时,两个答案错误,就俩对的)

求救

2024/11/25 22:49
加载中...