VioletaBabel

1011번: Fly me to the alpha centauri 본문

백준/백준-C++
1011번: Fly me to the alpha centauri
Beabletoet 2017. 1. 27. 14:09

#include <iostream>

using namespace std;

int main()

{

int T, x, y, m, count = 0, plus=1;

bool two = 0;

cin >> T;

for (int i = 0; i < T; ++i)

{

cin >> x >> y;

m = y - x;

for (int j = 0; j < m;++count)

{

if (two == 0)

{

j += plus;

two = 1;

}

else

{

j += plus;

++plus;

two = 0;

}

}

cout << count << endl;

count = 0; plus = 1; two = 0;

}

}


=====시간 초과..



#include <iostream>

using namespace std;

int main()

{

int T, spd=1, count=0;

long long x, y, m;

cin >> T;

for (int i = 0; i < T; ++i)

{

cin >> x >> y;

m = y - x;

while (m > 0)

if (m >= (spd * 2))

{

count += 2;

m -= (spd * 2);

++spd;

}

else

{

++count;

m -= spd;

--spd;

}

cout << count << endl;

spd = 1; count = 0;

}

}

'백준 > 백준-C++' 카테고리의 다른 글

1924번: 2007년  (0) 2017.01.27
10250번: ACM 호텔  (0) 2017.01.27
1193번: 분수찾기  (0) 2017.01.27
2292번: 벌집  (0) 2017.01.27
2438번: 별찍기 - 1  (0) 2017.01.27
Comments