20250619-20 baekjoon C

This commit is contained in:
songyc macbook 2025-06-20 18:08:35 +09:00
parent 47c13e44d4
commit 80115f2f03
6 changed files with 182 additions and 0 deletions

View File

@ -0,0 +1,41 @@
#include <stdio.h>
int main() {
char board[51][51];
int N, M, cnt1, cnt2, min, res=64;
scanf("%d %d",&N,&M);
for(int i=0; i<N; i++) {
scanf("%s",board[i]);
}
for(int i=0; i<N-7; i++) {
for(int j=0; j<M-7; j++) {
cnt1 = 0;
cnt2 = 0;
for(int n=0; n<8; n++) {
for(int m=0; m<8; m++) {
if((n+m)%2==0){
if(board[i+n][j+m]!='W') cnt1++;
if(board[i+n][j+m]!='B') cnt2++;
}
else{
if(board[i+n][j+m]!='B') cnt1++;
if(board[i+n][j+m]!='W') cnt2++;
}
}
}
min = cnt1>cnt2 ? cnt2 : cnt1;
if(min<res) {
if(min==0) {
printf("0\n");
return 0;
}
res = min;
}
}
}
printf("%d\n", res);
return 0;
}

View File

@ -0,0 +1,26 @@
#include <stdio.h>
int main() {
int N;
scanf("%d",&N);
char Str[8];
int n=666, cnt=0;
while(1) {
sprintf(Str,"%d", n);
for(int i=0; Str[i+2]!='\0'; i++) {
if(Str[i]=='6' && Str[i+1]=='6' && Str[i+2]=='6') {
cnt++;
if(cnt==N) {
printf("%s\n",Str);
return 0;
}
break;
}
}
n++;
}
return 0;
}

View File

@ -0,0 +1,31 @@
#include <stdio.h>
int main() {
int a,b,c,d,e,f,temp,x,y;
scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
for(x=-999; x<1000; x++) {
if(b==0) {
if(a*x != c || e==0) continue;
temp = f - d*x;
if(temp%e==0) {
y = temp / e;
}
else continue;
}
else {
temp = c - a*x;
if(temp%b==0) {
y = temp / b;
}
else continue;
}
if(d*x+e*y==f){
printf("%d %d\n", x,y);
return 0;
}
}
return 0;
}

View File

@ -0,0 +1,31 @@
#include <stdio.h>
int main() {
int N;
scanf("%d",&N);
int n=N, cnt=0;
while(n!=0) {
cnt++;
n /=10;
}
int start = N - 9*cnt < 1 ? 1 : N - 9*cnt;
for(int i=start; i<N; i++) {
int res_sum=0, num = i;
while(num!=0) {
res_sum += num%10;
num/=10;
}
res_sum += i;
if(res_sum==N) {
printf("%d\n",i);
return 0;
}
}
printf("0\n");
return 0;
}

View File

@ -0,0 +1,33 @@
#include <stdio.h>
int main() {
int N, M, flag=0, sum_temp, result=0;
int arr[100];
scanf("%d %d",&N, &M);
for(int i=0; i<N; i++) {
scanf("%d",arr+i);
}
for(int i=0; i<N; i++) {
if(flag) break;
for(int j=i+1; j<N; j++) {
if(flag) break;
for(int k=j+1; k<N; k++) {
sum_temp = arr[i] + arr[j] + arr[k];
if(sum_temp <= M) {
if(sum_temp > result) {
result = sum_temp;
if(result==M) {
flag = 1;
break;
}
}
}
}
}
}
printf("%d\n",result);
return 0;
}

View File

@ -0,0 +1,20 @@
#include <stdio.h>
int main() {
int N;
scanf("%d",&N);
int three, five = N/5;
while(five!=-1) {
if( (N-five*5)%3 == 0 ) {
three = (N-five*5)/3;
printf("%d\n",three+five);
return 0;
}
five--;
}
printf("-1\n");
return 0;
}