ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#191672 | #3394. 走路 | CHICHEN | 100 | 2ms | 1192kb | C++ | 671b | 2023-10-08 18:42:23 | 2023-10-08 22:02:34 |
answer
#include<bits/stdc++.h>
using namespace std;
long long n;
int fx[5] = {0,1,0,-1};
int fy[5] = {-1,0,1,0};
void dfs(int n,int &x,int &y)
{
for(int i = 1;i <= n;i++)
{
int cnt = i%4;
x = fx[cnt] * i + x;
y = fy[cnt] * i + y;
}
}
int main()
{
scanf("%d",&n);
int x,y;
x = y = 0;
if(n <= 1e8) dfs(n,x,y);
else{
if(n%4==0){
long long p = n/2;
printf("%d %d",-p,-p);
return 0;
}else{
int p = n%4;//p的值为1,2,3
if(p == 1) printf("%lld -%lld",n/2+1,n/2);
if(p == 2) printf("%lld %lld",n/2,n/2+1);
if(p == 3) printf("-%lld %lld",n/2+1,n/2+1);
return 0;
}
}
printf("%d %d",x,y);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1184kb
input:
3
output:
-2 2
result:
ok single line: '-2 2'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1184kb
input:
14
output:
7 8
result:
ok single line: '7 8'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1184kb
input:
29
output:
15 -14
result:
ok single line: '15 -14'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1184kb
input:
44
output:
-22 -22
result:
ok single line: '-22 -22'
Test #5:
score: 10
Accepted
time: 0ms
memory: 1188kb
input:
512
output:
-256 -256
result:
ok single line: '-256 -256'
Test #6:
score: 10
Accepted
time: 0ms
memory: 1184kb
input:
931
output:
-466 466
result:
ok single line: '-466 466'
Test #7:
score: 10
Accepted
time: 0ms
memory: 1184kb
input:
777777
output:
388889 -388888
result:
ok single line: '388889 -388888'
Test #8:
score: 10
Accepted
time: 2ms
memory: 1184kb
input:
989898
output:
494949 494950
result:
ok single line: '494949 494950'
Test #9:
score: 10
Accepted
time: 0ms
memory: 1188kb
input:
132431
output:
-66216 66216
result:
ok single line: '-66216 66216'
Test #10:
score: 10
Accepted
time: 0ms
memory: 1192kb
input:
1998244353
output:
999122177 -999122176
result:
ok single line: '999122177 -999122176'
Extra Test:
score: 0
Extra Test Passed