zoukankan      html  css  js  c++  java
  • Walking around Berhattan

    #include<iostream>
    using namespace std;
    const int maxn=100+10;
    const int dx[]={-1,0,1,0};
    const int dy[]={0,1,0,-1};
    int B[maxn][maxn]={0};
    bool pass[maxn][maxn]={0};
    int Pass(int x, int y)
    {
    	int ans =B[x][y];
    	if(pass[x][y]) ans/=2;
    	pass[x][y]=true;
    	return ans;
    }
    int value(int x, int y,int d)
    {
    	int ans = 0;
    	switch(d)
    	{
    		case 0:ans=Pass(x-1,y-1)+Pass(x-1,y);break;
    		case 1:ans=Pass(x-1,y)+Pass(x,y);break;
    		case 2:ans=Pass(x,y-1)+Pass(x,y);break;
    		case 3:ans=Pass(x-1,y-1)+Pass(x,y-1);break;
    
    	}
    return ans;
    }
    int main()
    {
    	int n,m;
    	cin>>n>>m;
    	for(int i = 1; i<=n; i++)
    	for(int j=1;j<=m ;j++)
    	{
    		char t;cin>>t;
    		B[i][j]=t-'0';
    	}
    	int x =1, y=1, ans=0,d=1;
            char t;
    	while(cin>>t)
    	{
    		if(t=='#')break;
    		switch(t)
    		{
    			case'M': ans+=value(x,y,d);
    			x +=dx[d];y+=dy[d];break;
    			case'L': d--;if(d<0) d=3;break;
    			case'R': d++;if(d>3) d=0;break;
    		}
    	}
    	cout<<ans<<endl;
    	return 0;
    }
    

      http://acm.sgu.ru/problem.php?contest=0&problem=463,以每个block左上顶点为参考计算坐标。。

  • 相关阅读:
    牛逼的博客地址
    动画的keyPath
    跳转到系统设置的各种配置
    UITextField只允许输入正数
    冒泡排序
    number类型的数组
    正则表达式
    C中常用的数学函数
    利用运行时,查看一个类的所有子类
    玉蟾宫(悬线法)
  • 原文地址:https://www.cnblogs.com/LyningCoder/p/3673608.html
Copyright © 2011-2022 走看看