题意巨难懂。简言之,就是球互相碰撞时,主动碰撞的球将会停止,另一个球将沿着碰撞方向继续移动,不断碰撞。但是无法弹射紧挨着的球,但是若a弹射b,bc相邻,这种情况b可以弹射c。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; #define MAXN 10 typedef struct {
int x, y;
char d;
} node_t; node_t nodes[];
char map[MAXN][MAXN];
int on;
// U < L < R < D.
int dir[][] = {-,,,-,,,,}; bool check(int x, int y) {
return x<||x>=||y<||y>=;
} char getDir(int k) {
if (k==) return 'U';
if (k==) return 'L';
if (k==) return 'R';
return 'D';
} bool dfs(int n) {
int i, j, k, x, y;
bool flag; if (n == )
return true; for (i=; i<; ++i) {
for (j=; j<; ++j) {
if (map[i][j] == 'O') {
for (k=; k<; ++k) {
x = i + dir[k][];
y = j + dir[k][];
if (check(x, y) || map[x][y]=='O')
continue;
flag = false;
while (!check(x, y)) {
if (map[x][y] == 'O') {
flag = true;
map[x][y] = 'X';
map[x-dir[k][]][y-dir[k][]] = 'O';
}
x += dir[k][];
y += dir[k][];
}
if (flag) {
map[i][j] = 'X';
nodes[n].x = i;
nodes[n].y = j;
nodes[n].d = getDir(k);
if (dfs(n-))
return true;
do {
x -= dir[k][];
y -= dir[k][];
if (map[x][y] == 'O') {
map[x][y] = 'X';
map[x+dir[k][]][y+dir[k][]] = 'O';
}
} while (x!=i || y!=j);
map[i][j] = 'O';
}
}
}
}
} return false;
} int main() {
int i = , j;
int t = ; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%s", &map[i]) != EOF) {
for (i=; i<; ++i)
scanf("%s", &map[i]);
on = ;
for (i=; i<; ++i)
for (j=; j<; ++j)
if (map[i][j] == 'O')
++on;
dfs(on-); if (t != )
printf("\n");
printf("CASE #%d:\n", ++t);
for(i=on-; i>=; --i)
printf("%d %d %c\n", nodes[i].x, nodes[i].y, nodes[i].d);
getchar();
i = ;
} return ;
}

【HDOJ】3500 Fling的更多相关文章

  1. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  2. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  3. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  4. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  5. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  6. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

  7. 【HDOJ】【3530】Subsequence

    DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...

  8. 【HDOJ】【3068】最长回文

    Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...

  9. 【HDOJ】【1512】Monkey King

    数据结构/可并堆 啊……换换脑子就看了看数据结构……看了一下左偏树和斜堆,鉴于左偏树不像斜堆可能退化就写了个左偏树. 左偏树介绍:http://www.cnblogs.com/crazyac/arti ...

随机推荐

  1. url传递中文的解决方案

    本文转载:http://www.cnblogs.com/ghd258/archive/2005/10/23/260241.html url传递中文的解决方案 1.设置web.config文件. < ...

  2. rsyslog安装

    http://www.rsyslog.com/downloads/download-other/ http://www.rsyslog.com/download/stable-download/pag ...

  3. 多线程(NSThread、NSOperation、GCD)编程浅谈

    一.基本概念 进程:一个具有一定独立功能的程序关于某个数据集合的一次运行活动.可以理解成一个运行中的应用程序.线程:程序执行流的最小单元,线程是进程中的一个实体.同步:只能在当前线程按先后顺序依次执行 ...

  4. Android开发艺术探索》读书笔记 (12) 第12章 Bitmap的加载和Cache

    第12章 Bitmap的加载和Cache 12.1 Bitmap的高速加载 (1)Bitmap是如何加载的?BitmapFactory类提供了四类方法:decodeFile.decodeResourc ...

  5. 解决下载android sdk慢的问题

    修改host文件 203.208.46.146 dl.google.com 203.208.46.146 dl-ssl.google.com 强制不使用https访问 在sdk manager里选择t ...

  6. Python分类统计数据

    在数据的常见分布中,有一种是一对多存储的数据,即一个是key,其他改key对应的多个value.例如气象数据等,每天有很多组,又或者是一个球员,他每天得多少分等等.我做这个东西有三种方法,即:常规编程 ...

  7. TCP和SSL

    查看TCP和SSL的握手时间: curl -w "TCP handshake: %{time_connect}, SSL handshake: %{time_appconnect}\n&qu ...

  8. MemCache缓存和C#自带的Cache缓存

    1.MemCache: //初始化 static SockIOPool _pool; // 创建Memcached private static MemcachedClient Create(stri ...

  9. mssql sql高效关联子查询的update 批量更新

    /* 使用带关联子查询的Update更新     --1.创建测试表 create TABLE Table1     (     a varchar(10),     b varchar(10),   ...

  10. javaScript 手写图片轮播

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...