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 |
真诡异??难道有什么神秘测试数据??谁帮我看看代码或是给些测试数据#include <stdio.h> #include <stdlib.h> struct stick{ int l; int w; }a[5001]; int account(int n); int main(void) { int ncase, i, ndata, j, k; struct stick key, temp; while (scanf("%d", &ncase) == 1) { for (i = 0; i < ncase; i++) { scanf("%d", &ndata); for (j = 0; j < ndata; j++) scanf("%d%d", &a[j].l, &a[j].w); /*插入排序*/ for (j = 1; j < ndata; j++) { key = a[j]; for (k = j-1; key.w < a[k].w && k >= 0; k--) { a[k + 1] = a[k]; } a[k + 1] = key; if (a[k].w == a[k + 1].w && a[k].l > a[k + 1].l) { temp = a[k]; a[k] = a[k + 1]; a[k + 1] = temp; } } /*for (j = 0; j < ndata; j++) printf("(%2d, %2d)", a[j].l, a[j].w);*/ printf("%d\n", account(ndata)); } } return 0; } int account(int n) { int i, sum, pos; sum = 0; i = 0; pos = 0; while (i < n) { while(i + 1 < n && a[i].l <= a[i + 1].l) { i++; pos = i + 1; } sum++; i++; } return sum; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator