Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机
题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走,
如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合
题解:我们可以选择一个边角的位置,每次都让一个怪移动到那里,同时暴力维护剩下的怪的位置,暴力走就可以了
不过后面发现好像直接随机也能过去? 下面我们队3个人的...
#include <iostream>
#include<string>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
char puzzle[][];
int kangaroo[][];
bool tag[][];
string ans;
int n, m;
const int a[][] = { {,},{-,},{,},{,-} };
const string moving[] = { "D","U","R","L" };
struct node {
int x, y;
string c;
};
node start;
queue<node> fuck;
string moveway[][];
string addmove(int x)
{
if (x == )
return moving[];
if (x == )
return moving[];
if (x == )
return moving[];
return moving[];
}
bool check(int x, int y)
{
if (x > && x <= n && y > && y <= m && puzzle[x][y] != '')
return true;
else
return false;
}
int guess_sum=;
bool check_around(int x, int y)
{
int sum = ,j;
for (int i = ; i < ; i++)
{
int ax = x + a[i][];
int ay = y + a[i][];
if (check(ax, ay) && kangaroo[ax][ay] == )
{
sum++;
j = i;
}
}
if (sum==)
{
guess_sum = j;
return true;
}
else
return false;
}
void BFS()
{
while (!fuck.empty())
{
node tmp = fuck.front();
fuck.pop();
for (int i = ; i < ; i++)
{
int x = tmp.x + a[i][];
int y = tmp.y + a[i][];
if (check(x, y) && kangaroo[x][y] == && tag[x][y] == false)
{
node new_node;
new_node.x = x;
new_node.y = y;
new_node.c = addmove(i) + tmp.c;
moveway[x][y] = new_node.c;
tag[x][y] = true;
fuck.push(new_node);
}
}
}
}
node needmove;
bool judge()
{
needmove.c = "";
for (int i = ; i <= n; i++)
for (int j = ; j <= m; j++)
if (i != start.x || j != start.y)
{
if (kangaroo[i][j] > )
{
if (needmove.c == "" || needmove.c.size() < moveway[i][j].size())
{
needmove.x = i;
needmove.y = j;
needmove.c = moveway[i][j];
}
}
}
if (needmove.c != "")
return false;
return true;
}
void movex(int& x, int y, char c)
{
if (c == 'U'&&x - > && puzzle[x - ][y] != '')
x--;
if (c == 'D'&&x + <= n && puzzle[x + ][y] != '')
x++;
}
void movey(int x, int& y, char c)
{
if (c == 'L'&&y - > && puzzle[x][y - ] != '')
y--;
if (c == 'R'&&y + <= m && puzzle[x][y + ] != '')
y++;
}
void movekangaroo()
{
int tmp[][];
for (int k = ; k < needmove.c.size(); k++)
{
for (int i = ; i <= n; i++)
for (int j = ; j <= m; j++)
tmp[i][j] = kangaroo[i][j];
char c = needmove.c[k];
for (int i = ; i <= n; i++)
for (int j = ; j <= m; j++)
if (kangaroo[i][j] > )
{
int newx = i, newy = j;
tmp[i][j] = ;
movex(newx, newy, c);
movey(newx, newy, c);
tmp[newx][newy] = ;
}
for (int i = ; i <= n; i++)
for (int j = ; j <= m; j++)
kangaroo[i][j] = tmp[i][j];
}
}
int len = ;
int main()
{
int i, j, k;
ios::sync_with_stdio(false);
cin.tie();
cin >> n >> m;
for (i = ; i <= n; i++)
for (j = ; j <= m; j++)
cin >> puzzle[i][j];
memset(kangaroo, , sizeof(kangaroo));
int sum = ;
for (i = ; i <= n; i++)
for (j = ; j <= m; j++)
if (puzzle[i][j] == '')
{
sum++;
kangaroo[i][j] = ;
}
if (sum == || sum == )
{
cout << "L\n";
return ;
}
for (i = ; i <= n; i++)
for (j = ; j <= m; j++)
if (kangaroo[i][j] == && check_around(i, j))
{
start.x = i;
start.y =j;
start.c = "";
}
for (i = ; i <= n; i++)
for (j = ; j <= m; j++)
moveway[i][j] = "";
memset(tag, false, sizeof(tag));
fuck.push(start);
tag[start.x][start.y] = true;
BFS();
/*for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
if (kangaroo[i][j] > 0)
cout << i << " " << j << " " << moveway[i][j] << endl;
}*/
ans = "";
while (!judge() && len < ) //get needmove
{
len += needmove.c.size();
ans += needmove.c;
movekangaroo();
/* cout << needmove.x << " " << needmove.y << " "<<needmove.c<<endl;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
cout << puzzle[i][j];
for (j = 1; j <= 20; j++)
cout << " ";
for (j = 1; j <= m; j++)
cout << kangaroo[i][j];
cout << endl;
}
cout << endl;*/
}
if (len == )
ans = ans + "R";
cout << ans << "\n";
}
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%lld",&x)
using namespace std;
ll s[][];
int main()
{
ll n,m,i,j,k;
sl(n);sl(m);
for(i = ;i < n;i++)
scanf("%s",s[i]);
srand(time());
char ans[] = {'L','R','D','U'};
int l = ,r = ;
for(i = ;i <= ;i++)
{
char ch = ans[rand()%];
printf("%c",ch);
}
puts("");
return ;
}
#include<bits/stdc++.h> using namespace std; #define mem(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
const int maxn=;
int n,m;
char s[maxn][maxn];
int a[maxn][maxn];
int b[maxn][maxn];
int p[]={,,,-};
int q[]={,-,,};
char ch[]={'L','R','U','D'};
int deg(int x,int y) {
int res=;
rep(i,,) {
int xx=x+p[i];
int yy=y+q[i];
if(xx<||xx>=n||yy<||yy>=m) continue;
if(s[xx][yy]=='') continue;
res++;
}
return res;
}
struct Node {
int x,y;
int step;
Node() {}
Node(int _x,int _y,int _step) {
x=_x;
y=_y;
step=_step;
}
};
bool vis[maxn][maxn];
int f[maxn][maxn];
queue<Node> Q; int main() {
scanf("%d%d",&n,&m);
rep(i,,n-) scanf("%s",s[i]);
int ex,ey;
int sum=;
rep(i,,n-) {
rep(j,,m-) {
if(s[i][j]=='') a[i][j]=;
else {
a[i][j]=;
sum++;
}
}
}
if(sum==) return *puts("");
rep(i,,n-) {
rep(j,,m-) {
if(s[i][j]==''&°(i,j)==) {
ex=i;
ey=j;
}
}
}
// printf("%d %d\n",ex,ey);
// puts("");
int epoch=;
int t=;
while(t<=) {
if(a[ex][ey]==sum) break;
mem(vis,);
mem(f,-);
while(!Q.empty()) Q.pop();
Node start(ex,ey,);
Q.push(start);
vis[ex][ey]=;
int sx=ex,sy=ey,step=;
while(!Q.empty()) {
Node o=Q.front();
Q.pop();
if(step<o.step&&a[o.x][o.y]) {
step=o.step;
sx=o.x;
sy=o.y;
}
rep(i,,) {
int x=o.x+p[i];
int y=o.y+q[i];
if(x<||x>=n||y<||y>=m) continue;
if(s[x][y]==''||vis[x][y]) continue;
Node node(x,y,o.step+);
f[x][y]=i;
vis[x][y]=;
Q.push(node);
}
}
// printf("%d %d\n",sx,sy);
// rep(i,0,n-1) {
// rep(j,0,m-1) {
// printf("%d ",a[i][j]);
// }
// puts("");
// }
while() {
if(sx==ex&&sy==ey) break;
int o=f[sx][sy];
printf("%c",ch[o]);
// printf("%d %d\n",sx,sy);
t++;
mem(b,);
rep(i,,n-) {
rep(j,,m-) {
if(s[i][j]=='') continue;
int x=i-p[o];
int y=j-q[o];
if(x<||x>=n||y<||y>=m||s[x][y]=='') {
b[i][j]+=a[i][j];
}
else {
b[x][y]+=a[i][j];
}
}
}
rep(i,,n-) {
rep(j,,m-) {
a[i][j]=b[i][j];
}
}
sx=sx-p[o];
sy=sy-q[o];
}
}
puts("");
return ;
}
Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机的更多相关文章
- Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP
题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...
- Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律
题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...
- Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流
题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...
- Gym - 101981D The 2018 ICPC Asia Nanjing Regional Contest D.Country Meow 最小球覆盖
题面 题意:给你100个三维空间里的点,让你求一个点,使得他到所有点距离最大的值最小,也就是让你找一个最小的球覆盖掉这n个点 题解:红书模板题,这题也因为数据小,精度也不高,所以也可以用随机算法,模拟 ...
- Gym - 101981J The 2018 ICPC Asia Nanjing Regional Contest J.Prime Game 计数
题面 题意:1e6的数组(1<a[i]<1e6), mul (l,r) =l × (l+1) ×...× r, fac(l,r) 代表 mul(l,r) 中不同素因子的个数,求s ...
- Gym - 101981A The 2018 ICPC Asia Nanjing Regional Contest A.Adrien and Austin 简单博弈
题面 题意:一堆有n个石子,编号从1⋯N排成一列,两个人Adrien 和Austin玩游戏,每次可以取1⋯K个连续编号的石子,Adrien先手,谁不能取了则输 题解:k==1时,显然和n奇偶相关,当k ...
- 2018 ICPC Asia Jakarta Regional Contest
题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . Ø Ø Ø Ø . Ο Ο:当场 Ø:已补 . : 待补 A. Edit Distance Thin ...
- The 2018 ACM-ICPC Asia Qingdao Regional Contest K XOR Clique
K XOR Clique BaoBao has a sequence a1,a2,...,an. He would like to find a subset S of {1,2,. ...
- 2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)
题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine ...
随机推荐
- SQL几种常用的函数
函数的种类: 算数函数(数值计算的函数) 字符串函数(字符串操作的函数) 日期函数(用来进行日期操作的函数) 转换函数(用来转换数据类型和值的函数) 聚合函数(用来进行数据聚合的函数) 算数函数(+- ...
- Requirejs常用配置和应用
requirejs.require方法冲突 如果加载了多个requirejs脚本,每个requirejs会判断是否浏览器已经实现了require和define方法.如果浏览器已经自带require和d ...
- 用C#在Visual Studio写Javascript单元测试(Firefox内核)
引用nuget包: 注意:Geckofx45 nuget包必须是最后引用,否则初始化会出错 编写JsRunner using Gecko; using System; using System.Col ...
- JS弹出子窗口
目的 在一个主窗口中,点击一个链接, 弹出一个子窗口 , 父窗口保留 在子窗口中点击关闭, 关闭子窗口. 子窗口的位置位于屏幕的中间 实现 main.html <!DOCTYPE html> ...
- EF入门
1.(安装EF)右键项目
- 前端领域的BEM到底是什么
前端领域的BEM到底是什么 BEM - Block Element Modfier(块元素编辑器) BEM方法确保每一个参加了同一网站开发项目的人,基于一套代码规范去开发,这样非常有利于团队成员理解彼 ...
- [API 开发管理] 分享几个 eoLinker 实用操作技巧
一键离线导出项目,PDF.WORD等格式任你挑选 举例说明,如果我要将 "示例素材项目" 导出到本地,并且以 PDF 的格式保存. 首先找到该项目所在空间:演示空间,在左边一级菜单 ...
- Mapreduce代码疑点(1)
一.Hadoop MultipleInputs.addInputPath 读取多个路径 https://blog.csdn.net/t1dmzks/article/details/76473905 M ...
- 洛谷——P1757 通天之分组背包
P1757 通天之分组背包 题目背景 直达通天路·小A历险记第二篇 题目描述 自01背包问世之后,小A对此深感兴趣.一天,小A去远游,却发现他的背包不同于01背包,他的物品大致可分为k组,每组中的物品 ...
- 学习MPI并行编程记录
简单的MPI程序示例 首先,我们来看一个简单的MPI程序实例.如同我们学习各种语言的第一个程序一样,对于MPI的第一个程序同样是"Hello Word". /* Case 1 he ...