本帖最后由 dolly_yos2 于 2023-2-5 20:05 编辑
不用 IDLE,好奇一下这两种方法是不是应该都可行?
魔法版:import os;os.execlp("python", "python")
正常版:
第二题没意思
第三题等待会再编辑上来(似乎并不需要登录,还是登录与否看到的内容不同(不会吧)?)
很快 C 就(终于)会有标准库中的 clz 之类的函数啦!#include <stdio.h>
#include <stdint.h>
static inline uint8_t count_effective_bits(uint32_t value){
uint8_t result = 0;
if(value > 0xffff){ result += 16; value >>= 16; }
if(value > 0xff){ result += 8; value >>= 8; }
if(value > 0xf){ result += 4; value >>= 4; }
switch(value){
case 7: case 6: case 5: case 4:
result += 1;
case 3: case 2:
result += 1;
case 1:
result += 1;
case 0:
break;
default:
result += 4;
break;
}
return result;
}
int main(){
scanf("%*u");
unsigned int n, k, m;
while(scanf("%u%u%u", &n, &k, &m) == 3){
if(k > m && n == 1){ printf("-1\n"); continue; }
if(k <= m){
printf("%u", k);
for(unsigned int i = 1; i < n; i++) printf(" 0");
putchar('\n');
continue;
}
uint8_t effective_bits = count_effective_bits(m);
unsigned int base = 1 << (effective_bits - 1);
unsigned int limit = (1 << effective_bits) - 1;
if(k > limit){ printf("-1\n"); continue; }
printf("%u %u", base, k - base);
for(unsigned int i = 2; i < n; i++) printf(" 0");
putchar('\n');
}
return 0;
}
|