频道栏目
首页 > 资讯 > C++ > 正文

cf#179(div.2)

13-03-05        来源:[db:作者]  
收藏   我要投稿
[cpp]  
/* 
 
A 题,方法:搜索 。。。 
题意:要求(0,0)到(x,y)要拐几个弯!!  
 
 
*/  
#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);  
    }  
}   
 
 
[cpp]  
/* 
 
B 题,方法:队列或者模拟。。。 
题意:求连续子段和不超过 t 的最大长度。。。 
 
 
*/   
#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 
 
 
*/  
 
相关TAG标签
上一篇:几个终端下超赞的小命令
下一篇:Vsftp配置文件详解
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站