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);
}
}