3 6174 1789 2005
0 3 7
3 6174 1789 2005
0 3 7
3 asvdge ef ofmdofn xvssc kxvbv hull full suua pmlu
f v ?
문제 : http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=110502&format=html
Status : Solved
#include <iostream> using namespace std; unsigned int reverse(unsigned int input); int main(void) { unsigned int numberOfTestcase, input, i; cin >> numberOfTestcase; for(i = 0; i < numberOfTestcase; i++) { int count = 0; cin >> input; if(input == reverse(input)) { cout << 0 << " " << input << endl; } else { while((input = input + reverse(input)) != reverse(input)) { count++; } cout << ++count << " " << input << endl; } } return 0; } unsigned int reverse(unsigned int input) { unsigned int result = 0; while(input > 0) { result *= 10; result += input % 10; input = input / 10; } return result; }
문제
Source Code
문제풀이 시간 : 10분(코딩 포함)
Solved 받아낼때까지 걸린 시간 : 1시간
그동안 Wrong Answer로 일관하던 Programming Challenges 로봇이 드디어 'Solved'를
뱉어냈다;;
문제는 경계값도 아니고 입력문제도 아니고 기본자료형의 최대크기문제???
Visual C++에서는 int형을 4바이트로 처리하기때문에 1,000,000이라는 숫자를 다룰 때 문제가
없지만 Programming Challenges의 로봇이 사용하는 컴파일러는 아마도 int형을 2바이트로
처리하는듯 하다.
그래서 65535를 넘어가면 문제를 일으켜서 'Wrong Answer'를 뱉어낸것 같다.
하지만 Runtime이 3초가 넘는걸 보면 알고리즘을 엄청나게 비효율적으로 설계한듯;;
Best Time이 0.008초로 나와있는데....대체 어떻게 알고리즘을 설계했길래 저런 시간이
나올 수 있는겐지;;
암튼 오랫동안 답을 얻지 못했던 문제를 풀어서 뿌듯하다.(물론 오래전에 문제를 풀긴 했으나
로봇덕분에 삽질을 계속 했었다;)
Source Code
Sample Test Case
Source Code
Sample Test Case
Source Code
Sample Input
A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts of money. Each of these friends might or might not give some money to any or all of the other friends. Likewise, each friend might or might not receive money from any or all of the other friends. Your goal in this problem is to deduce how much more money each person gives than they receive.
The rules for gift-giving are potentially different than you might expect. Each person sets aside a certain amount of money to give and divides this money evenly among all those to whom he or she is giving a gift. No fractional money is available, so dividing 3 among 2 friends would be 1 each for the friends with 1 left over -- that 1 left over stays in the giver's "account".
In any group of friends, some people are more giving than others (or at least may have more acquaintances) and some people have more money than others.
Given a group of friends, no one of whom has a name longer than 14 characters, the money each person in the group spends on gifts, and a (sub)list of friends to whom each person gives gifts, determine how much more (or less) each person in the group gives than they receive.
The grader machine is a Linux machine that uses standard Unix conventions: end of line is a single character often known as '\n'. This differs from Windows, which ends lines with two charcters, '\n' and '\r'. Do not let your program get trapped by this!
Line 1: | The single integer, NP | |||
Lines 2..NP+1: | Each line contains the name of a group member | |||
Lines NP+2..end: | NP groups of lines organized like this:
|
`Ad hoc' problems are those whose algorithms do not fall into standard categories with well-studied solutions. Each ad hoc problem is different; no specific or general techniques exist to solve them.
Of course, this makes the problems the `fun' ones, since each one presents a new challenge. The solutions might require a novel data structure or an unusual set of loops or conditionals. Sometimes they require special combinations that are rare or at least rarely encountered.
Ad hoc problems usually require careful reading and usually yield to an attack that revolves around carefully sequencing the instructions given in the problem.
Ad hoc problems can still require reasonable optimizations and at least a degree of analysis that enables one to avoid loops nested five deep, for example.
More ad hoc problems appear on this web site than any other kind of problem. Always be ready for an ad hoc problem if you can not classify a problem as one of the other standard types (to be listed later).