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 |
题目中的测试数据和几位大牛提供的需要注意的数据都过了,但还是WA! C语言新手向各位大牛求教#include<stdio.h> int main() { int n,i,j,p,q,x,y,b[1010]; float a[1010]; scanf("%d",&n); p=0; for(i=1;i<=n;i++) { scanf("%f",&a[i]); b[i]=1; if(p<a[i]) { p=a[i]; //求出最高者地号码p q=i; } } for(i=1;i<=p-1;i++) { for(j=1;j<i;j++) { if(a[i]>a[j]&&b[j]+1>b[i]) { b[i]=b[j]+1; } } } x=0; for(i=1;i<=n;i++) { if(x<b[i]) { x=b[i]; } } //对1到p-1号求出最长上升子列的长度x for(i=p;i<=n;i++) { for(j=p;j<i;j++) { if(a[i]<a[j]&&b[j]+1>=b[i]) { b[i]=b[j]+1; } } } y=0; for(i=1;i<=n;i++) { if(y<b[i]) { y=b[i]; //对p到n号求最长下降子列的长度y } } printf("%d",n-x-y); // n-x-y就是要出去的人 return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator