Uriel's Corner

Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
posts - 0, comments - 50, trackbacks - 0, articles - 594

POJ 3061 Subsequence---模拟

Posted on 2009-08-27 16:36 Uriel 阅读(227) 评论(0)  编辑 收藏 引用 所属分类: POJ模拟
没什么特殊技巧,用了两个变量当游标用
/*Problem: 3061  User: Uriel 
   Memory: 524K  Time: 79MS 
   Language: C++  Result: Accepted
*/
 

#include
<stdio.h>

int max,flag,i,x,y,n,sum,smx,num[100010],t;
int main()
{
    scanf(
"%d",&t);
    
while(t--)
    
{
        scanf(
"%d %d",&n,&sum);
        
for(i=0;i<n;i++)
        
{
            scanf(
"%d",&num[i]);
        }

        x
=0;
        y
=0;
        flag
=1;
        max
=100000;
        smx
=num[0];
        
while(y<&& x<=y) 
        
{
            
if(smx<sum)
            
{
                y
++;
                flag
++;
                smx
+=num[y];
            }

            
else if(smx>=sum)
            
{
                
if(max>flag)max=flag;
                flag
--;
                x
++;
                smx
-=num[x-1];
            }

        }

        
if(max==100000)max=0;
        printf(
"%d\n",max);
    }

    
return 0;
}



只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理