CSU 1510: Happy Robot 1511: 残缺的棋盘 1513: Kick the ball!

1510: Happy Robot
#include<iostream>
#include<cstring>
#include<cstdio>
#define INF 9999
using namespace std;
char str[1050];

int Min(int a,int b,int c)
{
    if(a>b)
        a=b;
    if(a>c)
        a=c;
    return a;
}

int Max(int a,int b,int c)
{
    if(a<b)
        a=b;
    if(a<c)
        a=c;
    return a;
}

void change(int* t,int dir)
{
    int tt=t[0];
    if(dir)
    {
        t[0]=t[3];
        t[3]=t[1];
        t[1]=t[2];
        t[2]=tt;
    }
    else
    {
        t[0]=t[2];
        t[2]=t[1];
        t[1]=t[3];
        t[3]=tt;
    }
}

int main()
{
    int len;
    int t[4];
    int Case=1;
    while(~scanf("%s",str))
    {
        int a[4]= {0,-INF,-INF,-INF};
        int b[4]= {0,INF,INF,INF};
        int c[4]= {0,-INF,-INF,-INF};
        int d[4]= {0,INF,INF,INF};
        len=strlen(str);
        for(int i=0; i<len; i++)
        {
            if(str[i]=='F')
            {
                a[0]++,a[1]--;
                b[0]++,b[1]--;
                c[2]++,c[3]--;
                d[2]++,d[3]--;
            }
            else if(str[i]=='L')
            {
                change(a,1);
                change(b,1);
                change(c,1);
                change(d,1);
            }
            else if(str[i]=='R')
            {
                change(a,0);
                change(b,0);
                change(c,0);
                change(d,0);
            }
            else
            {
                t[0]=Max(a[0]+1,a[2],a[3]);
                t[1]=Max(a[1]-1,a[2],a[3]);
                t[2]=Max(a[0],a[1],a[2]);
                t[3]=Max(a[0],a[1],a[3]);
                memcpy(a,t,16);
                t[0]=Min(b[0]+1,b[2],b[3]);
                t[1]=Min(b[1]-1,b[2],b[3]);
                t[2]=Min(b[0],b[1],b[2]);
                t[3]=Min(b[0],b[1],b[3]);
                memcpy(b,t,16);
                t[0]=Max(c[0],c[2],c[3]);
                t[1]=Max(c[1],c[2],c[3]);
                t[2]=Max(c[0],c[1],c[2]+1);
                t[3]=Max(c[0],c[1],c[3]-1);
                memcpy(c,t,16);
                t[0]=Min(d[0],d[2],d[3]);
                t[1]=Min(d[1],d[2],d[3]);
                t[2]=Min(d[0],d[1],d[2]+1);
                t[3]=Min(d[0],d[1],d[3]-1);
                memcpy(d,t,16);
            }
        }
        t[0]=max(Max(a[0],a[1],a[2]),a[3]);
        t[1]=min(Min(b[0],b[1],b[2]),b[3]); 
        t[2]=max(Max(c[0],c[1],c[2]),c[3]);
        t[3]=min(Min(d[0],d[1],d[2]),d[3]);
        printf("Case %d: %d %d %d %d\n",Case++,t[1],t[0],t[3],t[2]);
    }
    return 0;
}


/**********************************************************************
	Problem: 1510
	User: 3901140225
	Language: C++
	Result: AC
	Time:20 ms
	Memory:2024 kb
**********************************************************************/


1511: 残缺的棋盘

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int r1,c1,r2,c2,r3,c3,head,flag,tail,tx,ty;
int vis[9][9];
int dx[8]={-1,-1,-1,0,0,1,1,1};
int dy[8]={-1,0,1,-1,1,-1,0,1};
int cnt=0;
struct node
{
    int x,y,f,s;
}a[200];
void bfs()
{
   head=1;
   tail=1;
   flag=0;
   a[tail].x=r1;
   a[tail].y=c1;
   a[tail].s=0;
   tail++;
   while(head<tail)
   {
       for(int k=0;k<8;k++)
       {
           tx=a[head].x+dx[k];
           ty=a[head].y+dy[k];
           if(tx==r3&&ty==c3||tx<1||ty<1||tx>8||ty>8)
            continue;
          if(vis[tx][ty]==0)
            {
                vis[tx][ty]=1;
                a[tail].x=tx;
                a[tail].y=ty;
                a[tail].s=a[head].s+1;
                tail++;
            }
           if(tx==r2&&ty==c2)
            {
               flag=1;
               break;
            }
            //cout<<tail<<endl;
       }
        if(flag)
            break;
     head++;

   }
   cout<<"Case "<<++cnt<<": "<<a[tail-1].s<<endl;
}

int main()
{
    int T=10010;
    while(scanf ("%d%d%d%d%d%d",&r1,&c1,&r2,&c2,&r3,&c3)==6)
    {
        memset(vis,0,sizeof(vis));
        vis[r1][c1]=1;
        bfs();
    }
    return 0;
}
/**********************************************************************
	Problem: 1511
	User: 3901140225
	Language: C++
	Result: AC
	Time:352 ms
	Memory:2028 kb
**********************************************************************/


1513: Kick the ball!

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
double p[11];
int a,b;
double ans;

void dfs(int x,int y,int k,double pl )
{
    if(pl<1e-6) return;
    if(k==10)
    {
        if(x==a&&y==b) ans+=pl;
        return;
    }
    if(y+(5-k/2)<x||x+(5-(k+1)/2)<y)//判断结束
    {
        dfs(x,y,k+1,pl);
        return;
    }
    if(k%2==0)//我
    {
        dfs(x+1,y,k+1,pl*p[k]);//球进
        dfs(x,y,k+1,pl*(1-p[k]));//不进
    }
    else//他
    {
        dfs(x,y+1,k+1,pl*p[k]);
        dfs(x,y,k+1,pl*(1-p[k]));
    }
}

int main()
{
    int num=1;
    while(scanf("%lf",&p[0])!=EOF)
    {
        ans=0;
        for(int i=1;i<5;i++)
            scanf("%lf",&p[2*i]);
        for(int i=0;i<5;i++)
            scanf("%lf",&p[2*i+1]);
        scanf("%d-%d",&a,&b);
        dfs(0,0,0,1.0);
        printf("Case %d: %.2f%%\n",num++,100*ans);
    }
    return 0;
}
/**********************************************************************
	Problem: 1513
	User: 3901140225
	Language: C++
	Result: AC
	Time:4 ms
	Memory:2024 kb
**********************************************************************/

猜你喜欢

转载自blog.csdn.net/nameofcsdn/article/details/80270356