ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1005. Куча камней

why carsh?
Послано liulian 2 ноя 2007 22:25
#include<stdio.h>
#include<stdlib.h>
int split(int st[],int low,int high){                                         /*____________________*/
           int    k,i=low;
           int    temp;
           int    x=st[low];
                  for(k=low+1;k<=high;k++)
                            if (st[k]<=x){
                                        i=i+1;
                                        if(i!=k){
                                                 temp=st[i];
                                                 st[i]=st[k];                                                /*___sort____*/
                                                 st[k]=temp;
                                        }
                            }
                 {temp=st[low];st[low]=st[i];st[i]=temp;}
         return i;
}
void sort(int st[],int low,int high){
         int   k;
                 if(low<high){
                              k=split(st,low,high);
                              sort(st,low,k-1);
                              sort(st,k+1,high);
                 }
}                                                                                       /*___________________*/
int main()
{    int  i,j,stone;                   /*the number of stone*/
     int weight[20]={0};
     int sum,average;
     int min,max,value,temp=0;
                  while(scanf("%d",&stone)!=EOF){
                                   for(sum=0,i=1;i<=stone;i++){
                                                 scanf("%d",&weight[i]);
                                                 sum=sum+weight[i];
                                   }
                                   average=sum/2;
                                   sort(weight,1,stone);
                                   for(max=0,i=1;i<=stone;i++){
                                                 max=max+weight[i];
                                                 if(max>=average) break;
                                   }
                                   for(min=0,j=i+1;j<=stone;j++)
                                                min=min+weight[j];
                                   if(min>max){temp=max;max=min;min=temp;}
                                   for(value=sum,i=1;(max-min)>=0;i++){
                                                    if((max-min)<value) value=max-min;
                                                    max-=weight[i];
                                                    min+=weight[i];
                                   }
                                   printf("%d\n",value);
              }
     return 0;
}

Edited by author 02.11.2007 22:26

Edited by author 02.11.2007 22:26