wojiaocbj

cbj

Mar 21st, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.05 KB | None | 0 0
  1. /*
  2.  Author: 曹北健(37509)
  3.  Result: AC Submission_id: 4207447
  4.  Created at: Tue Mar 22 2022 09:47:33 GMT+0800 (China Standard Time)
  5.  Problem: 5416  Time: 483   Memory: 1988
  6. */
  7.  
  8. /*
  9.  Author: 曹北健(37509)
  10.  Result: TLE    Submission_id: 4207445
  11.  Created at: Tue Mar 22 2022 09:47:00 GMT+0800 (China Standard Time)
  12.  Problem: 5416  Time: 2677  Memory: 1736
  13. */
  14.  
  15. /*
  16.  Author: 曹北健(37509)
  17.  Result: AC Submission_id: 4204005
  18.  Created at: Mon Mar 21 2022 11:08:38 GMT+0800 (China Standard Time)
  19.  Problem: 5416  Time: 259   Memory: 2044
  20. */
  21.  
  22. #include <stdio.h>
  23. unsigned int a[114514] = { 0 };
  24. void reverse_array_u32(unsigned int *arr, int l, int r){
  25.     int i = l, j = r, t;
  26.     while(i < j){
  27.         t = arr[i];arr[i] = arr[j];arr[j] = t;
  28.         i++;j--;
  29.     }
  30. }
  31. void array_rotate_left_u32(unsigned int *arr, int n, int k){
  32.     reverse_array_u32(arr, 0, k - 1);
  33.     reverse_array_u32(arr, k, n - 1);
  34.     reverse_array_u32(arr, 0, n - 1);
  35. }
  36. void array_rotate_right_u32(unsigned int *arr, int n, int k){
  37.     reverse_array_u32(arr, 0, n - 1);
  38.     reverse_array_u32(arr, 0, k - 1);
  39.     reverse_array_u32(arr, k, n - 1);
  40. }
  41. int main(){
  42.     int n, i, k, tmp, bittomove, numtomove;
  43.     char dir[5] = { 0 };
  44.     unsigned int t, b0;
  45.     while(~scanf("%d", &n)){
  46.         for(i = 0;i < n;i++){
  47.             scanf("%d", &tmp);
  48.             a[i] = (unsigned int)tmp;
  49.         }
  50.         scanf("%s%d", dir, &t);
  51.         bittomove = t % 32;
  52.         numtomove = (t / 32) % n;
  53.         if(dir[0] == 'l'){
  54.             if(bittomove){
  55.                 b0 = a[0] >> (32 - bittomove);
  56.                 for(k = 0;k < n - 1;k++){
  57.                     a[k] = (a[k] << bittomove) | (a[k + 1] >> (32 - bittomove));
  58.                 }
  59.                 a[n - 1] = a[n - 1] << bittomove | b0;
  60.             }
  61.             array_rotate_left_u32(a, n, numtomove);
  62.         }
  63.         else{
  64.             if(bittomove){
  65.                 b0 = a[n - 1] & ((1 << bittomove) - 1);
  66.                 for(k = n - 1;k > 0;k--){
  67.                     a[k] = (a[k] >> bittomove) | ((a[k - 1] & ((1 << bittomove) - 1)) << (32 - bittomove));
  68.                 }
  69.                 a[0] = (a[0] >> bittomove) | (b0 << (32 - bittomove));
  70.             }
  71.             array_rotate_right_u32(a, n, numtomove);
  72.         }
  73.         for(i = 0;i < n;i++){
  74.             printf("%d ", (int)(a[i]));
  75.         }
  76.         putchar('\n');
  77.     }
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment