运行不了
a[a_len]=p;
什么意思,指针没赋值就引用。
搞这么复杂干吗,用个静态数组就好了
a[a_len]=p;
什么意思,指针没赋值就引用。
搞这么复杂干吗,用个静态数组就好了
#include<stdio.h> int main(void) { int i,j,k,k1,x,n,m,max_len=0,max,a_len=0; int y,a[100]={0},p[100]; while(1) { scanf("%d",&y); if(y==-1)break; a[a_len]=y; a_len++; } for(k=0;k<a_len-2;k++) { x=a[k]; n=1; for(i=k+1;i<a_len-1;i++) { if(x>a[i]) { m=a[i]; n=2; for(j=i+1;j<a_len;j++) { if(m>a[j]) { n++; m=a[j]; } } } if(max_len<n) { max_len=n; m=p[0]=max=a[k]; for(j=i,k1=1;j<a_len;j++) { if(m>a[j]) { p[k1]=a[j]; m=a[j]; k1++; } } if(k<a_len) p[k1]=-1; } if((a_len-i-1)<n)break; } if(a_len-2-k<max_len)break; } printf("%d\n",max_len); for(i=0;i<a_len;i++) { if(p[i]==-1)break; printf("%d ",p[i]); } printf("\n\n"); getch(); return 0; }
#include <stdio.h> #include <stdlib.h> #define N ((int)1e6 + 1) int n, a[N], bn, b[N], c[N], d[N]; int main(void) { int i, cur; while (scanf("%d", &n) == 1) { for (i = 0; i < n; ++i) scanf("%d", &a[i]); for (i = 0, bn = -1; i < n; ++i) { if (bn == -1 || a[i] <= b[bn]) b[cur = ++bn] = a[i]; else { int low = 0, high = bn, mid; while (mid = (low + high) >> 1, low + 1 < high) { if (a[i] < b[mid]) low = mid; else if (a[i] >= b[mid]) high = mid; } if (b[low] <= a[i]) b[cur = low] = a[i]; else b[cur = high] = a[i]; } c[cur] = i; d[i] = cur ? c[cur - 1] : -1; } cur = c[bn]; for (i = bn; i >= 0; --i) { b[i] = a[cur]; cur = d[cur]; } for (i = 0; i <= bn; ++i) printf("%d ", b[i]); putchar('\n'); } return 0; } /* cc: run += '<in' */