题意巨难懂。简言之,就是球互相碰撞时,主动碰撞的球将会停止,另一个球将沿着碰撞方向继续移动,不断碰撞。但是无法弹射紧挨着的球,但是若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. Flashback Query、Flashback Table(快速闪回查询、快速闪回表)

    Flashback Query闪回查询 flashback query是基于undo表空间的闪回,与之相关的参数如下: SQL> show parameter undo NAME         ...

  2. [CSS3] Using CSS Combinators to Identify Siblings and Descendants in CSS

    CSS combinators allows us to reference the DOM relationship between two or more elements in CSS. < ...

  3. 关于 java.util.concurrent 您不知道的 5 件事--转

    第 1 部分 http://www.ibm.com/developerworks/cn/java/j-5things4.html Concurrent Collections 是 Java™ 5 的巨 ...

  4. 汉诺塔III 递推题

    题目描述: 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到大顺序串着由64个圆盘构成的塔.目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动 ...

  5. 一行代码实现iOS序列化与反序列化(runtime)

    一.变量声明 为便于下文讨论,提前创建父类Biology以及子类Person: Biology: @interface Biology : NSObject { NSInteger *_hairCou ...

  6. POJ 2007 Scrambled Polygon 凸包

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7214   Accepted: 3445 ...

  7. 各种开发语言示例调用WebService接口

    ASP示例: <% uid="账号"pwd="密码"tos="13900041123"msg="你们好"url = ...

  8. 安装ZendDebugger 调试php

    一直懒得装断点调试工具,平时调试就用echo var_dump debug_print_backtrace 搞搞. 今天同事装了个xdebug,看着眼馋.于是想自己也装一个,由于平时用zend stu ...

  9. Android VideoView

    这两天公司要让做一个播放视频的小Demo,于是网上学习了下VideoView的使用方法. 先看布局文件,很简单 就是一个VideoView和两个ImageView <RelativeLayout ...

  10. SQL Server 2008创建定期自动备份任务

    首先需要启动SQL Server Agent服务,这个服务如果不启动是无法运行新建作业的,点击“开始”–“所有程序”–“Microsoft SQL Server 2008”–“启动SQL Server ...