UVA 231 Testing the CATCHER【更正】

来源:互联网 发布:一叶而知天下秋 编辑:程序博客网 时间:2024/04/27 11:21

题目大意:输出最长递减子序列长度,LIS简单变形。

解题策略:LIS简单变形,注意输出和格式。

之前不注意把wa的代码贴上来,晕……


/*   UVA 231 Testing the CATCHER   AC by J.Dark   ON 2013/3/31   Time 0.008s*/#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 100000;int num[maxn], length[maxn];int testCase, numCount;/////////////////////void Solve(){     for(int i=1; i<=numCount; i++)  length[i] = 1;     for(int i=1; i<=numCount; i++){        for(int j=i+1; j<=numCount; j++){           if(num[j] < num[i]){  //严格递减               length[j] = max(length[j], length[i]+1);           }        }     }     int minAns = 0;     for(int i=1; i<=numCount; i++)        minAns = max(minAns, length[i]);     if(testCase > 1)   printf("\n");     printf("Test #%d:\n", testCase);  //控制格式      printf("  maximum possible interceptions: %d\n", minAns);}int main(){    int temp, endCount=0; //endCount控制输出。防止死循环     numCount = testCase = 0;    while((cin >> temp) && (endCount!=2))    {       if(temp != -1){          num[++numCount] = temp;          endCount = 0;       }else{          endCount++;          if(endCount != 2){             testCase++;             Solve();          }          numCount = 0;           }    }    //system("pause");    return 0;}



原创粉丝点击