2025-08-22 14:00:00 ~ 2025-11-22 16:00:00
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll solve(ll x)
{
if(x<10) return x+10;// 一位数
vector<int> nums;
while(x > 9)
{
bool flag = false;
for(int i=9; i>=2; --i)
{
if(x % i == 0)
{
flag = true;
nums.push_back(i);
x /= i;
break;
}
}
if(!flag)
{
return -1;
}
}
nums.push_back(x);
sort(nums.begin(), nums.end());
ll ans = 0;
for(int i=0; i<nums.size(); ++i)
{
ans = ans*10 + nums[i];
}
return ans;
}
int main()
{
int t;
cin >> t;
while(t--)
{
ll n;
cin >> n;
cout << solve(n) << endl;
}
return 0;
}
对于
对于
时间复杂度是:
对于
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int a[maxn];
int n;
int tong[maxn]; // 统计i出现的次数
void solve()
{
int maxx = 0;
for (int w = 2; w <= 200; w++)
{
int cnt = 0;
for (int i = 1; i <= 100; i++) // 假装选了i
{
if (w - i >= 1) // 说明另外一个一定存在
{
int x = i;
int y = w - i; // x + y == w
if (x > y)
continue;
// x和y能组装多少对
if (x == y) // 10 = 5 + 5
{
cnt += tong[x] / 2;
}
else // x y
{
cnt += min(tong[x], tong[y]);
}
}
}
cout << w << ' ' << cnt << endl;
maxx = max(maxx, cnt);
}
cout << maxx << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
tong[a[i]]++;
}
solve();
for (int i = 1; i <= 100; i++) // 清空
{
tong[i] = 0;
}
}
return 0;
}
对于
对于
直接单独考虑某个单独的命令是没有效果的,因为下一个命令会改变原来的方向。
考虑所有的命令执行一次之后,我们没有任何发现。
但是如果重复所有的命令执行四次,一定会保持原来的方向。(证明:假设每次执行所有命令之后,偏移的角度是
所以每4次命令序列使它产生的位移是相同的。我们暴力模拟4次命令序列,就能知道次命令序列的
行使它产生的位移,同时它现在恢复了初始的朝向,我们对
时间复杂度:
假设计算完成一次命令序列之后,我们可以直接知道按照原来方向的横向偏移量
其他方向也是按照这个标准进行计算的。
if (pos == 0)
{
tx += sx;
ty += sy;
}
if (pos == 1) // 关键
{
tx += sy;
ty -= sx;
}
if (pos == 2)
{
tx -= sx;
ty -= sy;
}
if (pos == 3) // 关键
{
tx -= sy;
ty += sx;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 5e5 + 7;
int a[maxn];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int n, t;
int sum = 0;
signed main()
{
cin >> n >> t;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum += a[i]; // 总步数,
}
int pos = 0; // 方向
int sx = 0;
int sy = 0; // 偏移
for (int i = 1; i <= n; i++) // 计算执行一次产生的位移
{
sx += dx[pos] * a[i];
sy += dy[pos] * a[i];
pos = (pos + a[i]) % 4;
}
pos = 0;
int tx = 0, ty = 0;
for (int i = 1; i <= t; i++) // 执行所有命令 t 次
{
pos = (pos + (sum % 4)) % 4;
if (pos == 0)
{
tx += sx;
ty += sy;
}
if (pos == 1) // 关键
{
tx += sy;
ty -= sx;
}
if (pos == 2)
{
tx -= sx;
ty -= sy;
}
if (pos == 3) // 关键
{
tx -= sy;
ty += sx;
}
}
cout << abs(tx) + abs(ty) << endl;
return 0;
}
思维难度:上位绿
对于
可以直接枚举立方数,然后暴力判断, 如果枚举
对于额外
此时的数据范围较大,我们可以考虑将
此时我们只需要将
也就是只需要三次方的选择,如果直接进行唯一分解定理,效率较低,我们可以先将质数筛选出来,然后进行判断,
又因为此时只需要找到三次方的选项,所以此时的时间复杂度是
对于
此时如果只靠上述的方法,无法通过所有数据,此时我们考虑枚举减少枚举的范围,
比如这里我们只筛选出来
此时的
又因为现在的数据范围是
肯定没有两个超过
又因为所有
所以如果
最后可以利用二分判断
简单来说,假设剩余的数字按照最坏情况考虑都是