编写程序的目的详情见链接:https://www.codechef.com/problems/COOKMACH/
错误
超出时限
Sub-Task Task # Score Result (time)
1 0 NA AC (0.000000)
1 1 NA TLE (1.010000)
1 2 NA TLE (1.010000)
1 3 NA TLE (1.010000)
Final Score -> 0.000000 Result - TLE
2 4 NA TLE (1.010000)
2 5 NA TLE (1.010000)
2 6 NA TLE (1.010000)
7 NA WA (0.000000)
最终得分 - 0.000000结果 - TLE
代码是
#include <stdio.h>
int main(void)
{
int test, set, des, a = 1, ctr = 0, str = 0, x;
scanf("%d", &test);
if (test > 0 && test <= 200)
{
for (x = 0; x < test; x++)
{
ctr = 0;
scanf("%d", &set);
scanf(" %d\n", &des);
if ((set > 0 && set <= 10000000) && (des > 0 && des <= 10000000))
{
if (set <= 100 && des <= 100)
{
if (set == des)
ctr = 0;
if (set == 1)
{
while (set != des)
{
set = set * 2;
ctr++;
}
}
else if (set != 1)
{
if (des % 2 == 0)
{
while (a < des)
{
a = a * 2;
str++;
}
}
if (a == des || des == 1)
{
if (set < des)
{
if (set % 2 == 0)
{
while (set != des)
{
set = set * 2;
ctr++;
}
}
else if (set % 2 == 1)
{
set = (set - 1) / 2;
ctr++;
while (set != des)
{
set = set * 2;
ctr++;
}
}
}
if (set > des)
{
if (set % 2 == 0)
{
while (set != des)
{
set = set / 2;
ctr++;
}
}
else if (set % 2 == 1)
{
set = (set - 1) / 2;
ctr++;
while (set != des)
{
set = set / 2;
ctr++;
}
}
}
}
}
}
printf("%d\n", ctr);
}
}
return 0;
}
}
答案 0 :(得分:0)
更多地关注按位移位和两个整数的按位交换等按位运算符。我的解决方案看起来像
#define swap(a, b) (a ^= b, b ^= a, a ^= b)
int main() {
long a, b;
int count, T;
scanf("%d", &T);
while (T--) {
scanf("%ld%ld", &a, &b);
for (count = 0; a & (a - 1); a >>= 1)
++count;
if (a > b)
swap(a, b);
for (; a < b; a <<= 1)
++count;
printf("%d\n", count);
}
return 0;
}
答案 1 :(得分:0)
答案 2 :(得分:0)
使用这个:
C/C++
ios_base::sync_with_stdio(false);
cin.tie(NULL) ;
Python
import psyco
psyco.full()
Java 不要使用 Scanner 类,而是使用 BufferedReader
。