您的位置:首页 > 其它

HDU1257最少拦截系统

2014-10-28 15:01 232 查看
/*求有多少个降序子序列*/

#include<iostream>
using namespace std;

int main()
{
int n;
int a[1000];
while (cin >> n)
{
if (n == 0)
{
cout << 1 << endl;
continue;
}
for (int i = 0; i < n; ++i)
{
cin >> a[i];
}
int tem = 0, min = a[0];
there:
for (int i = 1; i < n; ++i)
{
if (a[i] != 0 && a[i] < min)
{
min = a[i];
a[i] = 0;
}
if (i == n - 1)
{
tem++;
for (int t = 1; t < n; ++t)
{
if (a[t] != 0)
{
min = a[t];
a[t] = 0;  //赋值后使其等于零
goto there;
}

}
}
}
cout << tem << endl;
}
return 0;
}


/*

看到一个算法比我精简的

#include<stdio.h>
#include<string.h>
int main()
{
int i,n,count,a[1005],res,max;
while (scanf("%d",&n)!=EOF)
{
for (i=1; i<=n; ++i)
{
scanf("%d",&a[i]);
}
res=0;
count=n;
while (count)
{
max=50000;
res++;
for (i=1; i<=n; ++i)
{
if (a[i]>0 && a[i]<max)
{
max=a[i];
a[i]=-1;
count--;
}
}
}
printf("%d/n",res);
}
return 0;
}


*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: