Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
代码提交失败(如下) ft.....#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator