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 |
我这个居然也能超时!!我比别人博客上的代码明明快些!!??/* ID: talenth1 PROG: p2823 LANG: C++ */ #include<stdio.h> #define maxn 1000001 #define oo 999999999 int i,j,n,k,a[maxn]; void datain() { scanf("%d%d",&n,&k); for(i=1;i<=n;i++) scanf("%d",&a[i]); } void work() { int k1=1,k2=1; int min=oo,max=-oo,p; for(i=1;i<=n-k+1;i++){ p=i; if(k1){ min=a[p]; for(j=2;j<=k;j++){ if(a[p+j-1]<min)min=a[p+j-1]; } } else if(a[p+k-1]<min)min=a[p+k-1]; if(a[p]==min)k1=1; else k1=0; printf("%d ",min); } printf("\n"); for(i=1;i<=n-k+1;i++){ p=i; if(k2){ max=a[p]; for(j=2;j<=k;j++){ if(a[p+j-1]>max)max=a[p+j-1]; } } else if(a[p+k-1]>max)max=a[p+k-1]; if(a[p]==max)k2=1; else k2=0; printf("%d ",max); } } int main() { datain(); work(); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator