Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

代码提交失败(如下) ft.....

Posted by ulam at 2005-06-21 16:11:26 on Problem 1020
#include <stdio.h>
void Sort(int* a, int dimension);
int Evaluate(int capacity, int *a, int dimension);

int main()
{
    int t;/*处理行数*/
    int s;/*容量 */
    int n;/*每一行元素个数 */
    int i,j;/*循环变量 */
    int a[11][17];
    scanf("%d",&t);
    for (i=0; i<t; i++)
    {
        scanf("%d%d", &s, &n);
        for (j=0; j<n; j++)
        {
            scanf("%d",&a[i][j]);
        }
        Sort(a[i], n);
        if (Evaluate(s,a[i],n))  printf("%s\n","KHOOOOB!");
        else                  printf("%s\n","HUTUTU!");
    }
    return 0;
}

void Sort(int* a, int dimension)
{
  int i,j;/*for loop*/
  int tmp;/*for exchange*/
  for (i=0; i<dimension-1; i++)
  { 
    for (j=i+1; j<dimension; j++)
    {
      if (a[i] < a[j]) { tmp=a[i]; a[i]=a[j]; a[j]=tmp;}
    }
  }        
}

int Evaluate(int capacity, int* a, int dimension)
{   int i;/*for loop */
    int flag = 1;/* 设置分配成功的标识 */
    int lengthnow = a[0];/* 定义并初绐化当前方形长度 */
    int capacity_left = capacity*capacity - lengthnow*lengthnow;/*定义并初绐化当前剩余容量 */
    for (i=1; i<dimension; i++)
    {
        if (a[i]==1) capacity_left -= 1;/*1*1格对分配并不影响 */
        /*大于一格的要考虑扩容问题,在当前正方形内可以分配则不扩容 */
        if (a[i]>1 && (a[i]*a[i]>capacity_left + lengthnow*lengthnow - capacity*capacity) )
                  { lengthnow += a[i];  capacity_left -= a[i]*a[i];}
        if (lengthnow > capacity) {flag=0; break;}/*分配失败 */
        if (capacity_left < 0)     {flag=0; break;}/*分配失败*/
    }
    
    return flag;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator