2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem 最长不下降序列
2017-09-24 18:56
417 查看
Let SS be
a sequence of integers s_{1}s1, s_{2}s2, ......, s_{n}sn Each
integer is is associated with a weight by the following rules:
(1) If is is negative, then its weight is 00.
(2) If is is greater than or equal to 1000010000,
then its weight is 55.
Furthermore, the real integer value of s_{i}si is s_{i}-10000si−10000 .
For example, if s_{i}si is 1010110101,
then is is reset to 101101 and
its weight is 55.
(3) Otherwise, its weight is 11.
A non-decreasing subsequence of SS is
a subsequence s_{i1}si1, s_{i2}si2, ......, s_{ik}sik,
with i_{1}<i_{2}\
...\ <i_{k}i1<i2 ... <ik,
such that, for all 1
\leq j<k1≤j<k,
we have s_{ij}<s_{ij+1}sij<sij+1.
A heaviest non-decreasing subsequence of SS is
a non-decreasing subsequence with the maximum sum of weights.
Write a program that reads a sequence of integers, and outputs the weight of its
heaviest non-decreasing subsequence. For example, given the following sequence:
8080 7575 7373 9393 7373 7373 1010110101 9797 -1−1 -1−1 114114 -1−1 1011310113 118118
The heaviest non-decreasing subsequence of the sequence is <73,
73, 73, 101, 113, 118><73,73,73,101,113,118> with
the total weight being 1+1+1+5+5+1
= 141+1+1+5+5+1=14.
Therefore, your program should output 1414 in
this example.
We guarantee that the length of the sequence does not exceed 2*10^{5}2∗105
A list of integers separated by blanks:s_{1}s1, s_{2}s2,......,s_{n}sn
A positive integer that is the weight of the heaviest non-decreasing subsequence.
题目是说找出一个值最大的序列,而这个序列的值的定义方式是对于负数,值为0。对于正数,如果小于10000,那么值就是1,否则为5。另外,如果大于10000,那么这个数要减去10000才是他真正在数列中的数(比如10101,在数列中也将其视为101)。然后将其排列出一个最长的序列,要求这个序列的值最大,且序列为不下降的序列。
处理的时候,对于负数,因为没有值,所以直接舍去不读入就可以了。对于正数,如果小于10000就正常读入,如果大于10000的话,先将这个数减去10000存入,因为这个数的值为5,所以再复制4次,存入这个数5次进去,这样就相当于处理了权值为5的问题,然后读入完之后求出最长不下降子序列就可以了。、
(PS:这个题输入是一组数据,比赛的时候我当成多组数据写了,然后写了很多getchar判断空格回车结束,结果TLE了两发改成一组数据才A了....)
下面AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[1000005];
int b[1000005],c[1000005];
int fin(int *t,int len,int n)
{
int left=0,right=len,mid=(left+right)/2;
while(left<=right)
{
if(n>=t[mid])
left=mid+1;
else if(n<t[mid])
right=mid-1;
else
return mid;
mid=(left+right)/2;
}
return left;
}
int main()
{
int n;
int i,j;
int k;
int m;
int t;
int len;
char g;
i=0;
while(scanf("%d",&m)!=EOF)
{
a[i]=m;
if(a[i]<0)
{
i--;
}
else if(a[i]>10000)
{
a[i]-=10000;
k=a[i];
for(j=1;j<=4;j++)
{
i++;
a[i]=k;
}
}
i++;
}
n=i;
/*for(i=0;i<n;i++)
{
cout<<"a["<<i<<"] = "<<a[i]<<endl;
}*/
b[0]=1;
c[0]=-1;
c[1]=a[0];
len=1;
for(i=1;i<n;i++)
{
j=fin(c,len,a[i]);
c[j]=a[i];
if(j>len)
len=j;
}
cout<<len<<endl;
return 0;
}
a sequence of integers s_{1}s1, s_{2}s2, ......, s_{n}sn Each
integer is is associated with a weight by the following rules:
(1) If is is negative, then its weight is 00.
(2) If is is greater than or equal to 1000010000,
then its weight is 55.
Furthermore, the real integer value of s_{i}si is s_{i}-10000si−10000 .
For example, if s_{i}si is 1010110101,
then is is reset to 101101 and
its weight is 55.
(3) Otherwise, its weight is 11.
A non-decreasing subsequence of SS is
a subsequence s_{i1}si1, s_{i2}si2, ......, s_{ik}sik,
with i_{1}<i_{2}\
...\ <i_{k}i1<i2 ... <ik,
such that, for all 1
\leq j<k1≤j<k,
we have s_{ij}<s_{ij+1}sij<sij+1.
A heaviest non-decreasing subsequence of SS is
a non-decreasing subsequence with the maximum sum of weights.
Write a program that reads a sequence of integers, and outputs the weight of its
heaviest non-decreasing subsequence. For example, given the following sequence:
8080 7575 7373 9393 7373 7373 1010110101 9797 -1−1 -1−1 114114 -1−1 1011310113 118118
The heaviest non-decreasing subsequence of the sequence is <73,
73, 73, 101, 113, 118><73,73,73,101,113,118> with
the total weight being 1+1+1+5+5+1
= 141+1+1+5+5+1=14.
Therefore, your program should output 1414 in
this example.
We guarantee that the length of the sequence does not exceed 2*10^{5}2∗105
Input Format
A list of integers separated by blanks:s_{1}s1, s_{2}s2,......,s_{n}sn
Output Format
A positive integer that is the weight of the heaviest non-decreasing subsequence.样例输入
80 75 73 93 73 73 10101 97 -1 -1 114 -1 10113 118
样例输出
14
题目是说找出一个值最大的序列,而这个序列的值的定义方式是对于负数,值为0。对于正数,如果小于10000,那么值就是1,否则为5。另外,如果大于10000,那么这个数要减去10000才是他真正在数列中的数(比如10101,在数列中也将其视为101)。然后将其排列出一个最长的序列,要求这个序列的值最大,且序列为不下降的序列。
处理的时候,对于负数,因为没有值,所以直接舍去不读入就可以了。对于正数,如果小于10000就正常读入,如果大于10000的话,先将这个数减去10000存入,因为这个数的值为5,所以再复制4次,存入这个数5次进去,这样就相当于处理了权值为5的问题,然后读入完之后求出最长不下降子序列就可以了。、
(PS:这个题输入是一组数据,比赛的时候我当成多组数据写了,然后写了很多getchar判断空格回车结束,结果TLE了两发改成一组数据才A了....)
下面AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[1000005];
int b[1000005],c[1000005];
int fin(int *t,int len,int n)
{
int left=0,right=len,mid=(left+right)/2;
while(left<=right)
{
if(n>=t[mid])
left=mid+1;
else if(n<t[mid])
right=mid-1;
else
return mid;
mid=(left+right)/2;
}
return left;
}
int main()
{
int n;
int i,j;
int k;
int m;
int t;
int len;
char g;
i=0;
while(scanf("%d",&m)!=EOF)
{
a[i]=m;
if(a[i]<0)
{
i--;
}
else if(a[i]>10000)
{
a[i]-=10000;
k=a[i];
for(j=1;j<=4;j++)
{
i++;
a[i]=k;
}
}
i++;
}
n=i;
/*for(i=0;i<n;i++)
{
cout<<"a["<<i<<"] = "<<a[i]<<endl;
}*/
b[0]=1;
c[0]=-1;
c[1]=a[0];
len=1;
for(i=1;i<n;i++)
{
j=fin(c,len,a[i]);
c[j]=a[i];
if(j>len)
len=j;
}
cout<<len<<endl;
return 0;
}
相关文章推荐
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem(最长不下降子序列变形)
- The Heaviest Non-decreasing Subsequence Problem 最长非递减子序列 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- L. The Heaviest Non-decreasing Subsequence Problem -最长不降子序列变形nlogn-2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 计蒜客 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛-L. The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L.The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem(最长非减子序列+思路)
- 2017ICPC南宁赛区网络赛 The Heaviest Non-decreasing Subsequence Problem (最长不下降子序列)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:L. The Heaviest Non-decreasing Subsequence Problem
- 最长不减子序列变形 The Heaviest Non-decreasing Subsequence Problem 南宁网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem (LIS)
- 2017 icpc 南宁赛区 L.The Heaviest Non-decreasing Subsequence Problem(LIS)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛The Heaviest Non-decreasing Subsequence Problem(线段树优化DP)
- The Heaviest Non-decreasing Subsequence Problem(2017南宁网络赛)
- The Heaviest Non-decreasing Subsequence Problem 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 常见问题