본문 바로가기

pku

PKU 2636. Electrical Outlets 전기 콘센트 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3730 Accepted: 2806 설명 Roy는 새 아파트로 막 이사왔다. 아파트는 사실 새 것은 아니고, 집에 전기가 들어오지 않는 시대로 거슬러 올라간 것처럼 착각할 수 있는 상태이다. Roy의 아파트는 벽붙이형 콘센트가 단 하나뿐이기 때문에 Roy는 그의 가전제품을 한번에 하나씩만 전원을 공급할 수 있다. Roy는 컴퓨터로 일하면서 동시에 TV를 보는 것을 좋아하고, 청소를 하면서 HiFi system 을 큰 소리로 듣는 것을 좋아하기 때문에, 하나의 콘센트만 사용하는 것은 기능이 아니다. 사실 그는 그의 모든 가전제품을 동시에 전부 콘센트에 꽂기를 원한다. 해답은 당연히 powe.. 더보기
PKU 1979. Red and Black. AC get~ #include #include #include using namespace std; char a[101][101]; int b[101][101]; int total, m, n; void __fastcall isMovable(int x, int y) { total++; b[x][y] = 1; if (x - 1 >= 0) { if (a[x - 1][y] == '.' && b[x - 1][y] == 0) { isMovable(x - 1,y); } } if (x + 1 = 0) { if (a[x][y - 1] == '.' && b[x][y - 1] ==.. 더보기
PKU 1979. Red and Black 빨간 것과 검은 것 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3868 Accepted: 2523 설명 정사각형의 타일이 덮어진 사각형 모양의 방이 있습니다. 각 타일은 빨간색 또는 검은색이 칠해져 있습니다. 한 남자가 검은색 타일 위에 서있습니다. 그 타일에서부터, 그는 붙어있는 4개의 타일중 하나로 움직일 수 있습니다. 단, 빨간색 타일로는 이동할 수 없으며 오로지 검은색 타일로만 이동할 수 있습니다. 위에서 설명한 방식으로 그 남자가 이동할 수 있는 검은색 타일을 세는 프로그램을 만드세요. 입력 입력할 것은 복합적인 데이터 집합들이 있습니다. 입력할 데이터 집합은 x- 축과 y- 축의 방향에 있는 타일의 갯수를 의미하는 두 개의 양정수로.. 더보기
PKU 1979. Red and Black Red and Black Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3868 Accepted: 2523 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. Write a program to count the number of .. 더보기
PKU 3094. Quicksum. AC #include #include main() { char string[256]; int i, lenth, sum; while(gets(string)) { if(strcmp(string,"#")==0) break; lenth=strlen(string); for(i=0, sum=0; i 더보기
PKU 3077. Rounders. AC get~ #include using namespace std; int main() { int cases, cipher, data, i; cin >> cases; for (i = 0; i > data; cipher = 10; while (data / cipher != 0) { data += cipher / 2; data /= cipher; data *= cipher; cipher *= 10; } cout 더보기
PKU 3094. Quick sum. AC get~ #include #include using namespace std; int main() { string temp; int sum, i; while(getline(cin, temp)) { if (temp[0] == '#') { break; } sum = 0; i = 0; while(temp[i] != '\0') { if (temp[i] == ' ') { i++; continue; } sum += (i + 1) * (temp[i] - 'A' + 1); i++; } cout 더보기
PKU 3094. Quicksum 고속합 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3382 Accepted: 2397 설명 검사합계는 데이터의 패킷을 검사하여 하나의 숫자로 되돌려 주는 알고리즘이다. 기본 구조는, 패킷이 변하면 검사합계 또한 변하고, 그러므로 검사합계는 전송상의 에러를 찾아내거나, 문서의 내용을 확인하거나, 그리고 바람직하지 않은 데이터의 변화를 찾아야 하는 수많은 경우에 필요된다. 이 문제에서는, 당신은 '고속합'이라고 불리는 검사합계 알고리즘을 충족시켜야 한다. 고속합 패킷은 대문자와 공백만을 허용한다. 그것은 언제나 시작과 끝을 대문자와 함께 한다. 반면에, 일반적인 공백과 문자는 , 연속적인 공백을 포함하여 어떤 조합도 만들 수 있다. 고속합은 각 .. 더보기
PKU 3094. Quicksum Quicksum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3382 Accepted: 2397 Description A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necess.. 더보기
PKU 3077. Rounders. AC #include #include main() { int n, lenth, i; char string[10]; scanf("%d",&n); while(n--) { scanf("%s",&string); lenth=strlen(string); i=lenth; while(--i) { if(string[i] >= '5') { string[i]='0'; string[i-1]+=1; } else { string[i]='0'; } } while(i 더보기
PKU 3077. Rounders Rounders Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3128 Accepted: 2031 Description For a given number, if greater than ten, round it to the nearest ten, then (if that result is greater than 100) take the result and round it to the nearest hundred, then (if that result is greater than 1000) take that number and round it to the nearest thousand, and so on ... Input Input to this p.. 더보기
PKU 3077. Rounders 정수화하는 것들 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3128 Accepted: 2031 설명 주어진 숫자에 대해서, 10보다 크다면, 가까운 십 단위로 정수화 시키고, 또 (만약 결과가 100보다 크다면) 결과를 가까운 백 단위로 정수화 시키고, 또 (만약 결과가 1000보다 크다면) 결과를 가까운 천 단위로 정수화 시키고, 그렇게 계속... 입력 이 문제의 입력은 정수화 시킬 숫자를 지시하는 하나의 정수 n을 포함하는 행에서 시작한다. 다음 n 행들은 각각 하나의 정수 x(0 더보기
PKU 2388. Who's in the Middle. AC #include main() { int n,arr[9999],i; scanf("%d",&n); for(i=0; i 더보기
PKU 2388. 누가 중간 녀석이냐? AC get~ #import int i=-1,buf[9999];int main(){while(cin>>buf[i++]);sort(buf,buf+i-1);cout 더보기
PKU 2388. Who's in the Middle 가운데 있는 것은 누구 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7089 Accepted: 4265 설명 FJ는 그의 소떼중 가장 평균적인 소를 찾으려 한다. 그는 이 '중앙값' 젖소가 우유를 얼마나 생산하는지를 알고 싶어한다: 젖소들중 절반은 우유 생산량의 중앙값보다 크거나 같게 ; 절반은 우유 생산량의 중앙값보다 작거나 같게 우유를 생산한다. 홀수인 젖소의 개체수를 N (1 더보기
PKU 2388. Who's in the Middle Who's in the Middle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7089 Accepted: 4265 Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' cow gives: half of the cows give as much or more than the median; half give as much or less. Given an odd number of cows N (1 더보기
PKU 1804. Brainman. AC #include main() { int arr[1000]; int cnt,i,j,k,cases,n,tmp; int sorted=1; scanf("%d",&cases); for(k=1;k 더보기
PKU 1804. 뇌인간(?) get AC~ #include #include using namespace std; int main() { int x, y, i, j, n, data, buf[1000], cnt; cin >> n; for (x = 1; x > data; cnt = 0; for (y = 0; y > buf[y]; } for (i = data - 2; i >= 0; i--) { for (j = 0; j buf[j + 1]) { cnt++; swap(buf[j], buf[j + 1]); } } } cout 더보기
PKU 1804. Brainman. 뇌인간(?) Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3041 Accepted: 1737 설명 배경 Raymond Babbitt은 동생 Charlie 를 미치도록 몰아댔다. 최근 Raymond는 246개의 이쑤시게를 바닥에 흩뿌려놓고는 힐끗힐끗 쳐다보기만 했다. 그리고 심지어는 포커 카드를 세기까지 했다. 찰리는 같은 방식으로 머리를 쓰게 해서 엿먹이고 싶어 한다. 문제 찰리가 생각한 것은 이러하다. N개의 숫자가 늘어진 수열이 있다고 하자. 목표는 이 수열이 최종적으로 정렬되게 하는 것인데, 한번에 이웃한 두개의 숫자밖에 바꿀 수 없다. 예를 들면 : Start with: 2 8 0 3 swap (2 8) 8 2 0 3 swap (2 0).. 더보기
PKU 1804. Brainman. Brainman Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3041 Accepted: 1737 Description Background Raymond Babbitt drives his brother Charlie mad. Recently Raymond counted 246 toothpicks spilled all over the floor in an instant just by glancing at them. And he can even count Poker cards. Charlie would love to be able to do cool things like that, too. He wants to beat his brother in a.. 더보기
PKU 2649. Factovisors. AC 소인수분해 #include #include int m,n; int is_prime(int m) { int i, sqrn; sqrn=sqrt(m); for(i=2 ; i1;) { if(a%i==0) { a/=i; count++; } if(a%i!=0 || a==1) { if(count>0) { if(n/i 더보기
PKU 2649. Factovisor. get AC -_- #include #include #define TRUE 1 #define FALSE 0 int m, n; int isPrime(int m) { int i; if(m 더보기
PKU 2649. Factovisors. AC #include #include int m,n; int is_prime(int m) { int i; if(m 더보기
PKU 2649. Factovisors. TLE #include #include int m,n; int is_prime(int a) { int i=2; int sqrn=sqrt(a); while(i 더보기
PKU 2649. Factovisors. TLE #include #include using namespace std; unsigned __int64 n; int GCD(int a, int b) { while (1) { if (a % b == 0 || b % a == 0) { break; } if (a > b) { a %= b; } else { b %= a; } } if (a % b == 0) { return b; } else { return a; } } bool isPrime(int a) { int i, limit; if (a n >> m) { if (....) { cout 더보기
재미있는 소스코드 하나 가져왔습니다. #include #include using namespace std; int main() { __int64 tc, num, i, j, x, k, l; __int64 a, b, c; cin>>tc; l = 1390000; while(tc--) { cin>>num; for (i = 1; ;i++) { a = (int)log10((double)i); b = (int)pow(10., (double)a); k = (a * b + (1 - b)/9) + (i - (b - 1)) * (a + 1); if (num = x * ((int)log10((double)x) + 1); x *= 10) { num -= x * ((int)log10((double)x) + 1); } x /= 9; a = (int)log10((dou.. 더보기
PKU 1844, Sum. AC #include int i,in,sum; int main() { do { scanf("%d",&in); }while(in100000); for(i=sum=0;;i++) { sum+=i; if(sum>=in && (sum-in)%2==0) { printf("%d\n",i); break; } } } Run ID User Problem Result Memory Time Language Code Length Submit Time 4114901 jht009 1844 Accepted 204K 0MS C 296B 2008-09-23 15:25:49 매트릭스 포기해도 되나요???????????????????????????????? 헣헣헣 GG 더보기
PKU 1844. Sum. AC get!~ #include int main() { int i, j, sum = 0; scanf("%d", &i); for (j = 1; j = i) { if (!((sum - i) % 2)) { printf("%d\n", j); break; } } } return 0; } 흐음. 이번에도 쉬운 문제이지요? 1부터 N까지 숫자를 나열해 두고, 각 숫자마다 부호를 아무렇게나 둔 다음, 부호까지 붙인 수들을 합해서 S가 되게 만들되, 그 N중 최소를 출력하는 겁니다. 제 솔루션은 간단합니다. 1부터 N까지의 합을 그냥 구합니다. -_-; 이 때 1부터 N까지의 합이 S보다 크다면, S는 1부터 N까지의 숫자중 몇개를 뽑아서 만들 수 있.. 더보기
PKU 1844. Sum. 합!? Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4816 Accepted: 3123 설명 1부터 N까지의 자연수를 생각해 봅시다. 여기에 부호를 붙여보도록 하지요.(+나 -). 그리고 그대로 더해버려서 합계 S를 만들어 봅시다. 문제는 S를 이루기 위한 이 자연수들의 최소 갯수를 구하는 것입니다. 1부터 N까지 모두 쓰되 부호는 마음대로 붙여서 S를 만들기 위해 가장 적은 개수의 숫자로 S를 구성할 수 있게 합시다. 주어진 합 S에 대하여, 1부터 N까지 부호는 마음대로 붙여 최소의 N이 되는 경우를 구해 N을 출력하세요. 입력 한 줄만 입력받되, 합인 S를 0보다는 크고 100000보다는 작은(0< S 더보기
PKU 1844. Sum. Sum Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4816 Accepted: 3123 Description Consider the natural numbers from 1 to N. By associating to each number a sign (+ or -) and calculating the value of this expression we obtain a sum S. The problem is to determine for a given sum S the minimum number N for which we can obtain S by associating signs for all numbers between 1 to N. For a.. 더보기