ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#211434 | #3805. 折纸游戏 | rua | 0 | 0ms | 0kb | C++11 | 3.0kb | 2024-08-11 12:48:24 | 2024-08-11 13:17:27 |
answer
#include <bits/stdc++.h>
#define inf INT_MAX
#define NN INT_MIN
typedef long long ll;
using namespace std;
int n, p1, p2;
int a[1005][1005], pos[1005];
bool pri[1000005], vis[100005];
int primes[1005], cnt, sum, l, r;
void init()
{
for (int i = 2; i <= 1005; i++)
{
if (vis[i] == 1)
continue;
pri[i] = 1;
for (int j = 1; j * i <= 1005; j++)
vis[i * j] = 1;
}
for (int i = 1; i <= 1005; i++)
if (pri[i] == 1)
primes[++cnt] = i;
}
int main()
{
#ifdef WHX_AK_IOI
freopen("data.in", "r", stdin);
// freopen("dataout.txt","w",stdout);
#endif
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
init();
cin >> n >> p1 >> p2;
sum = n;
l = 1, r = n;
for (int i = 1; i <= n; i++)
a[i][1] = i, pos[i] = 1;
while (sum != 1)
{
if (sum % 2 == 0)
{
sum /= 2;
if (p1 == 1)
{
int mid = l + r + 1 >> 1;
for (int i = mid; i <= r; i++)
{
while (pos[l + i - mid] != 0)
a[r - (i - mid)][++pos[r - (i - mid)]] = a[l + i - mid][pos[l + i - mid]--];
}
l = mid;
}
else
{
int mid = l + r >> 1;
for (int i = l; i <= mid; i++)
{
while (pos[mid + i - l + 1] != 0)
a[mid - (i - l)][++pos[mid - (i - l)]] = a[mid + i - l + 1][pos[mid + i - l + 1]--];
}
r = mid;
}
}
else if (sum % 2 == 1 && (pri[sum] == 1))
{
sum--;
if (p2 == 2)
{
while (pos[r] != 0)
a[r - 1][++pos[r - 1]] = a[r][pos[r]--];
r--;
}
else
{
while (pos[l] != 0)
a[l + 1][++pos[l + 1]] = a[l][pos[l]--];
l++;
}
}
else
{
int t = 1;
while (sum % primes[t] != 0)
t++;
t = primes[t];
int t1 = t;
t = sum / t1;
if (p2 == 1)
{
for (int i = 1; i <= t1; i++)
{
int mid = l + t, r1 = l + t * 2 - 1;
for (int j = mid; j = r1; j++)
{
while (pos[l + j - mid] != 0)
a[mid + r1 - j + 1][++pos[mid + r1 - j + 1]] = a[l + j - mid][pos[l + j - mid]--];
}
l = mid;
}
}
else
{
for (int i = t1; i >= 1; i--)
{
int mid = r - t, l1 = r - t * 2 + 1;
for (int j = l1; j <= mid; j++)
{
while (pos[mid + j - l1 + 1] != 0)
a[mid - (j - l1)][++pos[mid - (j - l1)]] = a[mid + j - l1 + 1][pos[mid + j - l1 + 1]++];
}
r = mid;
}
}
}
}
for (int i = n; i >= 1; i--)
cout << a[1][i] << endl;
// system("pause");
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Runtime Error
input:
15 2 2
output:
result:
Test #2:
score: 0
Runtime Error
input:
33 1 2
output:
result:
Test #3:
score: 0
Time Limit Exceeded
input:
450 2 1
output:
result:
Test #4:
score: 0
Time Limit Exceeded
input:
667 1 1
output:
result:
Test #5:
score: 0
Runtime Error
input:
960 2 2
output:
result:
Test #6:
score: 0
Runtime Error
input:
3000 2 1
output:
result:
Test #7:
score: 0
Runtime Error
input:
78125 1 2
output:
result:
Test #8:
score: 0
Runtime Error
input:
2022161 1 1
output:
result:
Test #9:
score: 0
Runtime Error
input:
4194304 1 1
output:
result:
Test #10:
score: 0
Runtime Error
input:
4999999 2 1