cf#179(div.2)

/*

A 题,方法:搜索 。。。
题意:要求(0,0)到(x,y)要拐几个弯!! 
题目lian接:http://codeforces.com/contest/279/problem/A 

*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
#define manx 10000


int sum,xx,yy;


void dfs(int x,int y){
    if(x>0 && y>0) {
        if(yy==y && xx<x && xx>=(-x)) { cout<<sum<<endl; return ; } 尼玛啊,这里等号标错了,WA了许久!!! 
        sum++; 
        dfs(-x,y); 
    }
    else if(x>0 && y<0) { 
        if(xx==x && yy<=(-y+1) && yy>y){ cout<<sum<<endl; return ; }
        sum++; 
        dfs(x,-y+1); 
    }
    else if(x<0 && y<0) { 
        if(yy==y && xx<=(-x+1) && xx>x){ cout<<sum<<endl; return ; }
        sum++; 
        dfs(-x+1,y); 
    }
    else if(x<0 && y>0) { 
        if(xx==x && yy>=(-y) && yy<y){ cout<<sum<<endl; return ; }
        sum++; 
        dfs(x,-y); 
    }
    else if(x==0 && y==0){ 
        if(yy==y && xx<=(x+1) && xx>x){ cout<<sum<<endl; return ; }
        sum++; 
        dfs(x+1,y); 
    }
    else if(x==1 && y==0) {
        if(xx==x && yy<=(y+1) && yy>y) { cout<<sum<<endl; return ; }         
        sum++;  
        dfs(x,y+1); 
    }
}


int main(){    
    while(cin>>xx>>yy){
        if(xx==0 && yy==0) { cout<<"0"<<endl; continue; }
        sum=0;
        dfs(0,0);
    }
} 


 

/*

B 题,方法:队列或者模拟。。。
题意:求连续子段和不超过 t 的最大长度。。。
题目链接:http://codeforces.com/contest/279/problem/B 

*/ 
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define manx 100009

int x[manx];
long long s[manx];

int main(){
    int n,t;
    while(cin>>n>>t){
        long long k=1,max=0,p;
        long long sum=0;
        for(int i=1;i<=n;i++){
           scanf("%d",&x[i]);
           sum += x[i];
           while(sum>t){
               p=i-k;
               if(max<p) max=p;
               sum -= x[k];
               k++;
           }
        }    
        if(sum<=t) {
            p=n-k+1;
            if(max<p) max=p;
        }
        cout<<max<<endl;
    }
}

/*

4 5 
3 1 2 1

4 6 
3 1 1 4


*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值