7 355
订阅者
-424 小时
-247 天
-10930 天
帖子存档
def solve(N):
sum_needed = (N * (N + 1)) // 2
k = ((N + 1) * (N + 2)) // 2
count = 0
total = 0
for i in range(N + 1, 0, -1):
if total >= sum_needed:
break
total += i
count += 1
return count
#Get_Ribbon
#BNY
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
int x=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++) {
arr[i] = sc.nextInt();
}
System.out.println(Arrays.binarySearch(arr,x)>=0 ? (Arrays.binarySearch(arr,x)):-1);
}
}
#BIRLASOFT
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = sc.nextInt();
}
double avg= 0;
int sum = 0;
for (int i = 0; i < K; i++) {
sum += arr[i];
}
avg = (double) sum / K;
for (int i = K; i < N; i++) {
sum = sum - arr[i - K] + arr[i];
double cur = (double) sum / K;
if (cur > avg) {
avg = cur;
}
}
System.out.printf("%.2f\n", avg);
sc.close();
}
}
#wipro BIRLASOFT
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int curSum=0;
for(int i=0;i<n;i++){
curSum+=arr[i];
if(curSum%(i+1)==0){
System.out.println("1 ");
}else{
System.out.println("0 ");
}
}
}
}
#BIRLASOFT
