Educational Codeforces Round 25 B. Five-In-a-Row
2017-07-17 15:34
344 查看
传送门
B. Five-In-a-Row
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice
puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.
Alice wins if some crosses in the field form line of length not smaller than 5. This line can
be horizontal, vertical and diagonal.
Input
You are given matrix 10 × 10 (10 lines
of 10 characters each) with capital Latin letters 'X' being
a cross, letters 'O' being a nought and '.' being an empty
cell. The number of 'X' cells is equal to the number of 'O' cells
and there is at least one of each type. There is at least one empty cell.
It is guaranteed that in the current arrangement nobody has still won.
Output
Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.
Examples
input
output
input
output
题意:这一步轮到你下棋了,如果你下了这步棋能满足5个以上的X棋子连通的话(横,竖,斜)就YES
idea:枚举每一个'.'位置,把这个'.'变成'X'然后从左到右 从上到下 从左上到右下 从右上到左下判断是否有5个棋子以上连通即可。可能代码有点长,因为我傻逼。
//china no.1
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define pi acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x) memset(x,0,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
//const int dx[]={-1,0,1,0,-1,-1,1,1};
//const int dy[]={0,1,0,-1,1,-1,1,-1};
const int maxn=1e3+5;
const int maxx=1e5+100;
const double EPS=1e-7;
const int MOD=10000007;
#define mod(x) ((x)%MOD);
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define W while
inline int Scan()
{
int res=0,ch,flag=0;
if((ch=getchar())=='-')flag=1;
else if(ch>='0' && ch<='9')res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0';
return flag ? -res : res;
}
char mapp[25][25];
int check(int x,int y)
{
if(x>=1&&x<=10&&y>=1&&y<=10&&mapp[x][y]=='X')
return 1;
return 0;
}
int val=0;
int main()
{
FOR(1,10,i)
cin>>mapp[i]+1;
FOR(1,10,i)
FOR(1,10,j)
{
if(mapp[i][j]=='.')
{
int flag=0;
mapp[i][j]='X';
int tx=1,ty=j;
FOR(1,10,k)
{
FOR(1,10,b)
{
tx=k;tx=b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx+z,ty))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
tx=i,ty=1;
FOR(1,10,k)
{
FOR(1,10,b)
{
ty=k;tx=b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx,ty+z))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
tx=1,ty=1;
FOR(1,10,k)
{
FOR(1,10,b)
{
ty=k;tx=b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx-z,ty+z))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
tx=10,ty=10;
FOR(1,10,k)
{
FOR(1,10,b)
{
ty=11-k;tx=11-b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx-z,ty-z))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
mapp[i][j]='.';
}
}
if(val)
puts("YES");
else puts("NO");
}
B. Five-In-a-Row
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice
puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.
Alice wins if some crosses in the field form line of length not smaller than 5. This line can
be horizontal, vertical and diagonal.
Input
You are given matrix 10 × 10 (10 lines
of 10 characters each) with capital Latin letters 'X' being
a cross, letters 'O' being a nought and '.' being an empty
cell. The number of 'X' cells is equal to the number of 'O' cells
and there is at least one of each type. There is at least one empty cell.
It is guaranteed that in the current arrangement nobody has still won.
Output
Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.
Examples
input
XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... ..........
output
YES
input
XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... ..........
output
NO
题意:这一步轮到你下棋了,如果你下了这步棋能满足5个以上的X棋子连通的话(横,竖,斜)就YES
idea:枚举每一个'.'位置,把这个'.'变成'X'然后从左到右 从上到下 从左上到右下 从右上到左下判断是否有5个棋子以上连通即可。可能代码有点长,因为我傻逼。
//china no.1
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define pi acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x) memset(x,0,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
//const int dx[]={-1,0,1,0,-1,-1,1,1};
//const int dy[]={0,1,0,-1,1,-1,1,-1};
const int maxn=1e3+5;
const int maxx=1e5+100;
const double EPS=1e-7;
const int MOD=10000007;
#define mod(x) ((x)%MOD);
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define W while
inline int Scan()
{
int res=0,ch,flag=0;
if((ch=getchar())=='-')flag=1;
else if(ch>='0' && ch<='9')res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0';
return flag ? -res : res;
}
char mapp[25][25];
int check(int x,int y)
{
if(x>=1&&x<=10&&y>=1&&y<=10&&mapp[x][y]=='X')
return 1;
return 0;
}
int val=0;
int main()
{
FOR(1,10,i)
cin>>mapp[i]+1;
FOR(1,10,i)
FOR(1,10,j)
{
if(mapp[i][j]=='.')
{
int flag=0;
mapp[i][j]='X';
int tx=1,ty=j;
FOR(1,10,k)
{
FOR(1,10,b)
{
tx=k;tx=b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx+z,ty))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
tx=i,ty=1;
FOR(1,10,k)
{
FOR(1,10,b)
{
ty=k;tx=b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx,ty+z))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
tx=1,ty=1;
FOR(1,10,k)
{
FOR(1,10,b)
{
ty=k;tx=b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx-z,ty+z))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
tx=10,ty=10;
FOR(1,10,k)
{
FOR(1,10,b)
{
ty=11-k;tx=11-b;
if(check(tx,ty))
{
FOR(0,4,z)
{
if(!check(tx-z,ty-z))
flag=1;
}
}
else continue;
if(flag==1)
{
flag=0;
continue;
}
else val=1;
}
}
mapp[i][j]='.';
}
}
if(val)
puts("YES");
else puts("NO");
}
相关文章推荐
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B Five-In-a-Row 基础题
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 25 B. Five-In-a-Row
- Educational Codeforces Round 6 C. Pearls in a Row
- Educational Codeforces Round 6-C. Pearls in a Row(贪心)
- Educational Codeforces Round 6 620C Pearls in a Row(stl)
- 【Educational Codeforces Round 6C】【DP or 贪心】Pearls in a Row n个数分最多区间使得每个区间都有重复数
- Educational Codeforces Round 6 C. Pearls in a Row