1 条题解
-
0
C++ :
#include<bits/stdc++.h> using namespace std; int a[1010],b[1010]; int main(){ int n,k,c,i,j,x; cin>>n>>k>>c; for(i = 1;i <= n;i++){ a[i] = i; } //洗牌 for(i = 1;i <= k;i++){ x = 1; for(j = 1;j <= n / 2;j++){ b[x] = a[j]; b[x + 1] = a[n / 2 + j]; x = x + 2; } //b数组拷贝会a数组 for(j = 1;j <= n;j++){ a[j] = b[j]; } } cout<<a[c]<<endl; return 0; }
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int num1 = scanner.nextInt(); int num2 = scanner.nextInt(); int num3 = scanner.nextInt(); // String str = new String(); int[] a = new int[num1]; int[] b = new int[num1]; int[] c = new int[num1]; double s1 = 0,s2 = 0,avg1,avg2; int[] count = new int[10000]; int flag = 0; long m; for (int i = 0; i < num1; i++) { a[i] = i+1; } for(int i = 1;i <= num2;i++){ for(int k = num1 / 2,j = 1;k < num1 && j < num1;k++,j+=2){ b[j] = a[k]; } for (int k = 0,j = 0;k < num1 && j < num1; k++,j+=2) { c[j] = a[k]; } for(int k = 0;k < num1;k+=2){ b[k] = c[k]; } for(int k = 0;k < num1;k++){ a[k] = b[k]; } } System.out.println(a[num3 - 1]); }public static void paiXu(int[] a,int length){ int temp; for(int i = 0;i < length - 1;i++){ for(int k = 0;k < length - i - 1;k++){ if(a[k] > a[k + 1]){ temp = a[k]; a[k] = a[k + 1]; a[k + 1] = temp; } } } } public static void paiXud(int[] a){ int temp; for(int i = 0;i < a.length - 1;i++){ for(int k = 0;k < a.length - i - 1;k++){ if(a[k] < a[k + 1]){ temp = a[k]; a[k] = a[k + 1]; a[k + 1] = temp; } } } } public static void paiXux(int[] a){ int temp; for(int i = 0;i < a.length - 1;i++){ for(int k = 0;k < a.length - i - 1;k++){ if(a[k] > a[k + 1]){ temp = a[k]; a[k] = a[k + 1]; a[k + 1] = temp; } } } } public static int MAX(int[] a){ int max = a[0]; for (int i = 0; i < a.length; i++) { if(max < a[i]){ max = a[i]; } } return max; } public static int MIN(int[] a){ int min = a[0]; for (int i = 0; i < a.length; i++) { if(min > a[i]){ min = a[i]; } } return min; } public static int sum(int a){ int x,s = 0; while(a != 0){ x = a % 10; s = s + x; a /= 10; } return s; } public static boolean isPrime(int a){ if(a <= 1)return false; else for(int i = 2;i <= Math.sqrt(a);i++){ if(a % i == 0)return false; }return true; } public static long qiuYu(long i){ long a; a = i % 10; return a; } }
Python :
sr=input().split() n=int(sr[0]) k=int(sr[1]) i=int(sr[2]) a=[0]*n for j in range(n): a[j]=j+1 b=[0]*n for j in range(k): for l in range(n//2): b[2*l]=a[l] b[2*l+1]=a[l+n//2] for l in range(n): a[l]=b[l] print(b[i-1])
- 1
信息
- ID
- 2471
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者