SlideShare a Scribd company logo
1 of 3
136


#include <stdio.h>


unsigned int num[3][1500];
unsigned int mul[3] = {2,3,5};


int main()
{
      int c[3], w[3];
      int i, j, p;
      unsigned int min, n;


      for( j=0 ; j<3 ; j++ )
           c[j] = w[j] = 0;


      // 현재 ugly number
      n = 1;
      // 2, 3, 5 중 이전에 선택한 배수
      p = 0;


      for( i=1 ; i<1500 ; i++ )
      {
           for( j=p ; j<3 ; j++ )
           {
                 // overflow 방지
                 if( c[j] < 1500 && n < 0x7FFFFFFF / mul[j] )
                     num[j][ c[j]++ ] = n * mul[j];
           }


           min = 0x7FFFFFFF;


           // 최소값 찾기
           for( j=0 ; j<3 ; j++ )
           {
                 if( num[j][ w[j] ] < min )
                 {
                     min = num[j][ w[j] ];
                     p = j;
                 }
}


           n = min;
           w[p]++;
      }


      printf( "The 1500'th ugly number is %d.n", n );


      return 0;
}


272


#include <stdio.h>


int main()
{
      int isopend;
      int a;


      isopend = 0;
      while( (a = getchar()) != -1 )
      {
           if( a == '"' )
           {
                  if( isopend )
                  {
                         isopend = 0;
                         printf( "''" );
                  }
                  else
                  {
                         isopend = 1;
                         printf( "``" );
                  }
           }
           else
                  putchar( a );
      }
}
591


#include <stdio.h>


int a[110];


int main()
{
      int i, n, t;
      int sum, mean;


      t = 0;


      while( scanf( "%d", &n ) == 1 )
      {
           if( !n )
                  break;


           mean = 0;


           for( i=0 ; i<n ; i++ )
           {
                  scanf( "%d", &a[i] );
                  mean += a[i];
           }


           mean = mean / n;
           sum = 0;


           for( i=0 ; i<n ; i++)
           {
                  if( a[i] > mean )
                      sum += a[i] - mean;
           }


           printf( "Set #%dnThe minimum number of moves is %d.nn", ++t, sum );
      }
      return 0;
}

More Related Content

What's hot (18)

PHPのすべらない話#3
PHPのすべらない話#3PHPのすべらない話#3
PHPのすべらない話#3
 
Var
VarVar
Var
 
Slides
SlidesSlides
Slides
 
Programas for
Programas forProgramas for
Programas for
 
Programs
ProgramsPrograms
Programs
 
Programs
ProgramsPrograms
Programs
 
16067 array programs
16067 array programs16067 array programs
16067 array programs
 
Bai lam chuong 3
Bai lam chuong 3Bai lam chuong 3
Bai lam chuong 3
 
Scanfill polygon
Scanfill polygonScanfill polygon
Scanfill polygon
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Play fair cipher
Play fair cipherPlay fair cipher
Play fair cipher
 
Multiplicacion de matrices
Multiplicacion de matricesMultiplicacion de matrices
Multiplicacion de matrices
 
bai tap-loi-giai-ngon-ngu-lap-trinh-c
 bai tap-loi-giai-ngon-ngu-lap-trinh-c bai tap-loi-giai-ngon-ngu-lap-trinh-c
bai tap-loi-giai-ngon-ngu-lap-trinh-c
 
contoh Program C++ tentang fungsi for
contoh Program C++ tentang fungsi forcontoh Program C++ tentang fungsi for
contoh Program C++ tentang fungsi for
 
Dasar c
Dasar cDasar c
Dasar c
 
Alocação Dinâmica em C
Alocação Dinâmica em CAlocação Dinâmica em C
Alocação Dinâmica em C
 
Wave ECG
Wave ECGWave ECG
Wave ECG
 
C Program : Sorting : Bubble,
C Program : Sorting : Bubble, C Program : Sorting : Bubble,
C Program : Sorting : Bubble,
 

Viewers also liked

Acmicpcseminar3
Acmicpcseminar3Acmicpcseminar3
Acmicpcseminar3yonsei
 
2007 Icpc2
2007 Icpc22007 Icpc2
2007 Icpc2yonsei
 
Acmicpcseminar4
Acmicpcseminar4Acmicpcseminar4
Acmicpcseminar4yonsei
 
Problemset
ProblemsetProblemset
Problemsetyonsei
 
Data Structure 1
Data Structure 1Data Structure 1
Data Structure 1yonsei
 
Data Structure 3
Data Structure 3Data Structure 3
Data Structure 3yonsei
 
2007 Icpc3
2007 Icpc32007 Icpc3
2007 Icpc3yonsei
 
Back to-school movies for parents
Back to-school movies for parentsBack to-school movies for parents
Back to-school movies for parentsmoyeavip
 

Viewers also liked (8)

Acmicpcseminar3
Acmicpcseminar3Acmicpcseminar3
Acmicpcseminar3
 
2007 Icpc2
2007 Icpc22007 Icpc2
2007 Icpc2
 
Acmicpcseminar4
Acmicpcseminar4Acmicpcseminar4
Acmicpcseminar4
 
Problemset
ProblemsetProblemset
Problemset
 
Data Structure 1
Data Structure 1Data Structure 1
Data Structure 1
 
Data Structure 3
Data Structure 3Data Structure 3
Data Structure 3
 
2007 Icpc3
2007 Icpc32007 Icpc3
2007 Icpc3
 
Back to-school movies for parents
Back to-school movies for parentsBack to-school movies for parents
Back to-school movies for parents
 

Sources

  • 1. 136 #include <stdio.h> unsigned int num[3][1500]; unsigned int mul[3] = {2,3,5}; int main() { int c[3], w[3]; int i, j, p; unsigned int min, n; for( j=0 ; j<3 ; j++ ) c[j] = w[j] = 0; // 현재 ugly number n = 1; // 2, 3, 5 중 이전에 선택한 배수 p = 0; for( i=1 ; i<1500 ; i++ ) { for( j=p ; j<3 ; j++ ) { // overflow 방지 if( c[j] < 1500 && n < 0x7FFFFFFF / mul[j] ) num[j][ c[j]++ ] = n * mul[j]; } min = 0x7FFFFFFF; // 최소값 찾기 for( j=0 ; j<3 ; j++ ) { if( num[j][ w[j] ] < min ) { min = num[j][ w[j] ]; p = j; }
  • 2. } n = min; w[p]++; } printf( "The 1500'th ugly number is %d.n", n ); return 0; } 272 #include <stdio.h> int main() { int isopend; int a; isopend = 0; while( (a = getchar()) != -1 ) { if( a == '"' ) { if( isopend ) { isopend = 0; printf( "''" ); } else { isopend = 1; printf( "``" ); } } else putchar( a ); } }
  • 3. 591 #include <stdio.h> int a[110]; int main() { int i, n, t; int sum, mean; t = 0; while( scanf( "%d", &n ) == 1 ) { if( !n ) break; mean = 0; for( i=0 ; i<n ; i++ ) { scanf( "%d", &a[i] ); mean += a[i]; } mean = mean / n; sum = 0; for( i=0 ; i<n ; i++) { if( a[i] > mean ) sum += a[i] - mean; } printf( "Set #%dnThe minimum number of moves is %d.nn", ++t, sum ); } return 0; }