- 第一题 https://vjudge.net/problem/UVA-100 暴力破解法
#include <stdio.h>
#include <stdlib.h>
typedef long long int ll;
坑点:后面数据类型 x3值可能会超int
int main()
{
int i, j;
while (scanf("%d%d", &i, &j) != EOF) {
int flag = 0;
int x1 = 0, x2 = 0;
ll x3 = 0;
if (i>j) {
int temp = i;
i = j;
j = temp;
flag = 1;
}
for (int k = i; k <= j; k++)
{
ll g = k;
ll c = 1;
while (g != 1)
{
if (g % 2 == 0) {
g = g / 2;
c++;
}
else {
g = g * 3 + 1;
c++;
}
}
if (x3<c)
{
x1 = i;
x2 = j;
x3 = c;
}
}
if (flag == 1) {
int temp = x1;
x1 = x2;
x2 = temp;
}
printf("%d %d %lld\n", x1, x2, x3);
}
}
坑点2:i,j未强调 i与j的大小 坑点3:最后输出时 要以原顺序输出