SDUT 2021 summer team contest 6th

A - Secrete Master Plan

水题,直接模拟。

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5+10;
int g[3][3];
int k[5];
bool check(int a[])
{
    for(int i=1;i<=4;i++)
    {
        if(a[i]!=k[i]) return false;
    }
    return true;
}
int main()
{
    int t,ss=0;
    cin>>t;
    while(t--)
    {
       for(int i=1;i<=2;i++)
       {
           for(int j=1;j<=2;j++)
           {
               cin>>g[i][j];
           }
       }
       for(int i=1;i<=4;i++)
            cin>>k[i];
       int a[5][5],flag=0;
       a[1][1]=g[1][1],a[1][2]=g[1][2],a[1][3]=g[2][1],a[1][4]=g[2][2];
       a[2][1]=g[2][1],a[2][2]=g[1][1],a[2][3]=g[2][2],a[2][4]=g[1][2];
       a[3][1]=g[2][2],a[3][2]=g[2][1],a[3][3]=g[1][2],a[3][4]=g[1][1];
       a[4][1]=g[1][2],a[4][2]=g[2][2],a[4][3]=g[1][1],a[4][4]=g[2][1];
       for(int i=1;i<=4;i++)
       {
           if(check(a[i]))
           {
               flag=1;
               break;
           }
       }
       ss++;
       printf("Case #%d: ",ss);
       if(flag) cout<<"POSSIBLE"<<endl;
       else cout<<"IMPOSSIBLE"<<endl;
    }
}
    

G - Ancient Go

题意:用x和o来模拟围棋,问能不能再下一个x子,使得某些o棋被围杀,如果可以输出possible。
在这里插入图片描述
思路:Bfs 找所有 o 的连通块 ,看一下这个连通块的边界,如果边界只存在一个" . " ,说明一步就可能被围杀。遍历用floodfill算法,每个连通块只遍历一次。

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;
#define x first
#define y second
char a[10][10];
typedef pair<int, int> PII;
int vis[100][100];
int ss[100][100];
int cnt=0;
int flag=0;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
void bfs(int x,int y)
{
    queue<PII> q;
    q.push({x,y});
    vis[x][y]=true;
    while(q.size())
    {
        auto t=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            int xx=t.x+dx[i];
            int yy=t.y+dy[i];
            if(a[xx][yy]=='.'&&!ss[xx][yy])
            { 
                cnt++;
                ss[xx][yy]=1;
            }
            else if(a[xx][yy]=='o'&&!vis[xx][yy]&&xx>=1&&xx<=9&&yy>=1&&yy<=9)
            {
                vis[xx][yy]=1;
                q.push({xx,yy});
            }
        }
    }
}

int main()
{
    int t;
    cin>>t;
    int m=0;
    while(t--)
    {
       memset(vis,0,sizeof vis);
       m++;
       flag=0;
       cnt=0;
       for(int i=1;i<=9;i++)
       {
          for(int j=1;j<=9;j++)
          cin>>a[i][j];
       }
       for(int i=1;i<=9;i++)
       {
          for(int j=1;j<=9;j++)
          {
              if(vis[i][j]) continue;
              if(a[i][j]=='o')
              {
                  bfs(i,j);
                  memset(ss,0,sizeof ss);
               //   cout<<"i="<<i<<" j= "<<j<<" "<<cnt<<endl;
                  if(cnt==1) {flag=1;break;}
                  cnt=0;
              }
          }
       }
       if(flag) printf("Case #%d: Can kill in one move!!!\n",m);
       else printf("Case #%d: Can not kill in one move!!!\n",m);
       
    }
    
}

L - Huatuo’s Medicine

签到题

#include <iostream>
#include <cstring>
#include <algorithm>
typedef long long LL;
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
PII ans[110];
int a[110];
int b[110];

int main()
{
    int t;
    cin>>t;
    int ct=0;
    while(t--)
    {
        int n;
        cin>>n;
        ct++;
        LL y=2*(n-1)+1;
        printf("Case #%d: %d\n",ct,y);
    }
        
}

H - Sudoku

数独

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值