gpt4 book ai didi

c - 查找k轮后的数组状态

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:06:09 25 4
gpt4 key购买 nike

<分区>

Code Chef Problem

Given array of N integers A and a number K. During a turn the maximal value over all Ai is chosen, let's call it MAX. Then Ai = MAX - Ai is done for every 1 <= i <= N. Find out how will the array look like after K turns.

Input

The numbers N and K are given in the first line of an input. Then N integers are given in the second line which denote the array A.

Output

Output N numbers on a single line. It should be the array A after K turns.

Constraints

1 <= N <= 10^5
0 <= K <= 10^9

Ai does not exceed 2 * 10^9 by it's absolute value.

Example

Input:

4 1
5 -1 7 0

Output:

2 8 0 7

这是我的代码。它在我的本地计算机(Dec C++ 5.5.1 OS Win8)中运行良好。过去 2 天我一直在考虑这个问题,但是当我将它上传到 code chef 时,它显示错误答案。请告诉我这段代码中缺少什么?

#include <stdio.h>

long long int find_largest(long long int A[], long size){
long int largest =A[0],i;

for(i=1;i<size;i++){
if(largest < A[i])
largest = A[i];
}
return largest;
}
int main(){
long long int A[100000],K,j,largest =0, temp,prev_largest = 0;
long N, i;
char eof_chk;
int flag = 0;

while(1){
scanf("%ld %lld",&N,&K);
for(i=0;i<N;i++)
scanf("%lld",&A[i]);
largest = find_largest(A,N);
// Processing...
for(j=1; j<=K; j++){
largest = find_largest(A,N);
if(prev_largest == largest){
if((K-j)%2 == 0){
for ( i = 0; i < N; i++ ){
temp = largest - A[i];
if(temp > 2000000000)
A[i] = -(2000000000 - temp + 2000000000 + 1);
else
A[i] = temp;
}
break;
}
else break;
}
else{
for ( i = 0; i < N; i++ ){
temp = largest - A[i];
if(temp > 2000000000)
A[i] = -(2000000000 - temp + 2000000000 + 1);
else
A[i] = temp;
}
prev_largest = largest;
}
}
// Start for formated printing
for(i=0;i<N;i++){
if(i == (N-1)){
printf("%lld",A[i]);
}
else
printf("%lld ",A[i]);
}
// End for formated printing
if(getchar() == EOF) {
break;
}
else
printf("\n");
}
return 0;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com