Wang Xifeng's Little Plot http://acm.hdu.edu.cn/showproblem.php?pid=5024

预处理出每个点八个方向能走的最远距离,然后枚举起点,枚举方向,每走一步都要枚举左转和右转的情况,因为预处理好了,所以可以直接算出来。

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. const int M=;
  5. char a[M][M];
  6. int n,dp[M][M][];
  7. int dx[]={-,-,,,,,,-};
  8. int dy[]={,,,,,-,-,-};
  9. bool inside(const int &x,const int &y){
  10. if(x>=&&x<n&&y>=&&y<n) return true;return false;
  11. }
  12. int getfar(int x,int y,int dir){
  13. int res=;
  14. while(true){
  15. x+=dx[dir];
  16. y+=dy[dir];
  17. if(!inside(x,y)||a[x][y]=='#') break;
  18. res++;
  19. }
  20. return res;
  21. }
  22. int turnleft(int dir){
  23. return (dir+)%;
  24. }
  25. int turnright(int dir){
  26. return (dir+)%;
  27. }
  28. int solve(int x,int y,int dir){
  29. int res=,step=,left=turnleft(dir),right=turnright(dir);
  30. while(true){
  31. x+=dx[dir];
  32. y+=dy[dir];
  33. if(!inside(x,y)||a[x][y]=='#') break;
  34. step++;
  35. res=max(res,step+dp[x][y][left]);
  36. res=max(res,step+dp[x][y][right]);
  37. }
  38. return res;
  39. }
  40. int main(){
  41. while(~scanf("%d",&n),n){
  42. for(int i=;i<n;i++){
  43. scanf("%s",a[i]);
  44. }
  45. for(int i=;i<n;i++){
  46. for(int j=;j<n;j++){
  47. for(int k=;k<;k++){
  48. if(a[i][j]=='#'){
  49. dp[i][j][k]=-;
  50. }
  51. else{
  52. dp[i][j][k]=getfar(i,j,k);
  53. }
  54. }
  55. }
  56. }
  57. int ans=;
  58. for(int i=;i<n;i++){
  59. for(int j=;j<n;j++){
  60. if(a[i][j]=='.'){
  61. for(int k=;k<;k++){
  62. int now=solve(i,j,k);
  63. ans=max(ans,now);
  64. }
  65. }
  66. }
  67. }
  68. printf("%d\n",ans);
  69. }
  70. return ;
  71. }

A Corrupt Mayor's Performance Art http://acm.hdu.edu.cn/showproblem.php?pid=5023

成段更新。

  1. #include<cstdio>
  2. #include<cstring>
  3. #define mt(a,b) memset(a,b,sizeof(a))
  4. #define lrrt int L,int R,int rt
  5. #define iall 1,n,1
  6. #define imid int mid=(L+R)>>1
  7. #define lson L,mid,rt<<1
  8. #define rson mid+1,R,rt<<1|1
  9. const int M=;
  10. struct T{
  11. int cover,lazy;
  12. }tree[M<<];
  13. void build(lrrt){
  14. tree[rt].cover=;
  15. tree[rt].lazy=;
  16. if(L==R) return ;
  17. imid;
  18. build(lson);
  19. build(rson);
  20. }
  21. void pushdown(int rt){
  22. if(tree[rt].lazy){
  23. tree[rt<<].lazy=tree[rt<<|].lazy=tree[rt<<].cover=tree[rt<<|].cover=tree[rt].lazy;
  24. tree[rt].lazy=;
  25. }
  26. }
  27. void pushup(int rt){
  28. tree[rt].cover=tree[rt<<].cover==tree[rt<<|].cover?tree[rt<<].cover:;
  29. }
  30. void update(int x,int y,int z,lrrt){
  31. if(x<=L&&R<=y){
  32. tree[rt].cover=tree[rt].lazy=z;
  33. return;
  34. }
  35. imid;
  36. pushdown(rt);
  37. if(mid>=x) update(x,y,z,lson);
  38. if(mid<y) update(x,y,z,rson);
  39. pushup(rt);
  40. }
  41. bool vis[];
  42. void query(int x,int y,lrrt){
  43. if(L==R){
  44. vis[tree[rt].cover]=true;
  45. return ;
  46. }
  47. imid;
  48. if(x<=L&&R<=y){
  49. if(tree[rt].cover){
  50. vis[tree[rt].cover]=true;
  51. return ;
  52. }
  53. pushdown(rt);
  54. query(x,y,lson);
  55. query(x,y,rson);
  56. return ;
  57. }
  58. pushdown(rt);
  59. if(mid>=x) query(x,y,lson);
  60. if(mid<y) query(x,y,rson);
  61. }
  62. int main(){
  63. int n,m,x,y,z;
  64. char op[];
  65. while(~scanf("%d%d",&n,&m),n|m){
  66. build(iall);
  67. while(m--){
  68. scanf("%s%d%d",op,&x,&y);
  69. if(op[]=='P'){
  70. scanf("%d",&z);
  71. update(x,y,z,iall);
  72. }
  73. else{
  74. mt(vis,);
  75. query(x,y,iall);
  76. bool flag=false;
  77. for(int i=;i<=;i++){
  78. if(vis[i]){
  79. if(flag) printf(" ");
  80. printf("%d",i);
  81. flag=true;
  82. }
  83. }
  84. puts("");
  85. }
  86. }
  87. }
  88. return ;
  89. }

Saving Tang Monk http://acm.hdu.edu.cn/showproblem.php?pid=5025

集齐m把钥匙,就可以拯救唐僧,没集齐也可以从他身上踩过去,拿钥匙必须从小到大拿,蛇只要杀一次,所以要记录钥匙的状态和蛇是否被杀的状态。bfs。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cctype>
  4. #include<queue>
  5. #define mt(a,b) memset(a,b,sizeof(a))
  6. using namespace std;
  7. const int M=;
  8. char a[M][M];
  9. int n,m;
  10. struct Snake{
  11. int x,y;
  12. }ts[];
  13. struct Q{
  14. int step,sta,x,y,snake;
  15. friend bool operator <(const Q &a,const Q &b){
  16. return a.step>b.step;
  17. }
  18. }now,pre;
  19. priority_queue<Q> q;
  20. bool vis[M][M][<<];
  21. int dx[]={,,,-};
  22. int dy[]={,-,,};
  23. int getkey(const int &psta,const int &x,const int &y){
  24. int ressta=psta;
  25. if(isdigit(a[x][y])){
  26. int his=a[x][y]-'';
  27. his=<<(his-);
  28. if(his-==psta){
  29. ressta|=his;
  30. }
  31. }
  32. return ressta;
  33. }
  34. int bfs(){
  35. int ls=;
  36. for(int i=;i<n;i++){
  37. for(int j=;j<n;j++){
  38. if(a[i][j]=='K'){
  39. now.x=i;
  40. now.y=j;
  41. }
  42. if(a[i][j]=='S'){
  43. ts[ls].x=i;
  44. ts[ls].y=j;
  45. ls++;
  46. }
  47. }
  48. }
  49. now.snake=;
  50. now.sta=;
  51. now.step=;
  52. mt(vis,);
  53. vis[now.x][now.y][now.sta]=true;
  54. int End=(<<m)-;
  55. while(!q.empty()) q.pop();
  56. q.push(now);
  57. while(!q.empty()){
  58. pre=q.top();
  59. q.pop();
  60. if(a[pre.x][pre.y]=='T'&&pre.sta==End) return pre.step;
  61. for(int i=;i<;i++){
  62. int tx=pre.x+dx[i];
  63. int ty=pre.y+dy[i];
  64. if(tx>=&&tx<n&&ty>=&&ty<n&&a[tx][ty]!='#'){
  65. now.sta=getkey(pre.sta,tx,ty);
  66. if(!vis[tx][ty][now.sta]){
  67. vis[tx][ty][now.sta]=true;
  68. now.x=tx;
  69. now.y=ty;
  70. now.snake=pre.snake;
  71. if(a[tx][ty]=='S'){
  72. int id=;
  73. for(int j=;j<ls;j++){
  74. if(ts[j].x==tx&&ts[j].y==ty){
  75. id=j;
  76. break;
  77. }
  78. }
  79. if((now.snake>>id)&){
  80. now.step=pre.step+;
  81. }
  82. else{
  83. now.snake|=(<<id);
  84. now.step=pre.step+;
  85. }
  86. }
  87. else{
  88. now.step=pre.step+;
  89. }
  90. q.push(now);
  91. }
  92. }
  93. }
  94. }
  95. return -;
  96. }
  97. int main(){
  98. while(~scanf("%d%d",&n,&m),n|m){
  99. for(int i=;i<n;i++){
  100. scanf("%s",a[i]);
  101. }
  102. int ans=bfs();
  103. if(ans==-) puts("impossible");
  104. else printf("%d\n",ans);
  105. }
  106. return ;
  107. }

end

2014 ACM/ICPC Asia Regional Guangzhou Online的更多相关文章

  1. HDU 5029 Relief grain(离线+线段树+启发式合并)(2014 ACM/ICPC Asia Regional Guangzhou Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5029 Problem Description The soil is cracking up beca ...

  2. hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)

    Mart Master II Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  3. HDU 5000 2014 ACM/ICPC Asia Regional Anshan Online DP

    Clone Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) Total Submiss ...

  4. 2014 ACM/ICPC Asia Regional Shanghai Online

    Tree http://acm.hdu.edu.cn/showproblem.php?pid=5044 树链剖分,区间更新的时候要用on的左++右--的标记方法,要手动扩栈,用c++交,综合以上的条件 ...

  5. 2014 ACM/ICPC Asia Regional Anshan Online

    默默的签到 Osu! http://acm.hdu.edu.cn/showproblem.php?pid=5003 #include<cstdio> #include<algorit ...

  6. 2014 ACM/ICPC Asia Regional 北京 Online

    G - Grade Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of mushroo ...

  7. 2014 ACM/ICPC Asia Regional Xi'an Online

    03 hdu5009 状态转移方程很好想,dp[i] = min(dp[j]+o[j~i]^2,dp[i]) ,o[j~i]表示从j到i颜色的种数. 普通的O(n*n)是会超时的,可以想到o[]最大为 ...

  8. HDU 5010 Get the Nut(2014 ACM/ICPC Asia Regional Xi'an Online)

    思路:广搜, 因为空格加上动物最多只有32个那么对这32个进行编号,就能可以用一个数字来表示状态了,因为只有 ‘P’   'S' 'M' '.' 那么就可以用4进制刚好可以用64位表示. 接下去每次就 ...

  9. HDU 5002 Tree(动态树LCT)(2014 ACM/ICPC Asia Regional Anshan Online)

    Problem Description You are given a tree with N nodes which are numbered by integers 1..N. Each node ...

随机推荐

  1. Spark基础排序+二次排序(java+scala)

    1.基础排序算法 sc.textFile()).reduceByKey(_+_,).map(pair=>(pair._2,pair._1)).sortByKey(false).map(pair= ...

  2. 会写网页 就会写手机APP -- Hybrid Mobile Apps for ASP.NET Developers

    您好,这篇文章是我的BLOG发出,原始出处在此: 会写网页 就会写手机APP -- Hybrid Mobile Apps for ASP.NET Developers http://www.dotbl ...

  3. jquery mobile最棘手的一个问题

    大多数jquery mobile开发的妹子们都碰到过这个问题: 如何调用loading效果   这里给出一段代码,赶紧练手吧. //显示loading function showLoading(){ ...

  4. python ssh

    使用python包paramiko实现通过ssh的安全远程访问 使用pip下载安装paramiko,提示会缺一个crypto包,用pip将这个包也安好,python就可以正常引用paramiko了 一 ...

  5. [div+css布局]命名规则

    //首页可能碰到的 页头:header登录条:loginBar标志:logo侧栏:sideBar广告:banner导航:nav子导航:subNav菜单:menu子菜单:subMenu搜索:search ...

  6. sublimeLinter-jshint 配置

    这几天知道sublime3有可以对javascript进行语法检查的文件,折腾了一上午,搞定了. 记录一下步骤: 1.先安装nodejs. 2.npm install jshint -g 3.通过su ...

  7. Oracle Database Concepts:介绍模式对象(Introduction to Schema Objects)

    数据库模式(schema)是数据结构的逻辑容器,被称作模式对象(schema objects) 每一个数据库用户拥有一个和用户名相同的模式,例如hr用户拥有hr模式. 在一个产品数据库中,模式的拥有者 ...

  8. JQuery ----文档处理

    1.append(content|fn) 概述 向每个匹配的元素内部追加内容. 这个操作与对指定的元素执行appendChild方法,将它们添加到文档中的情况类似. 2.appendTo(conten ...

  9. 社保系列11《ATR》

    1)  冷复位(Cold Reset) 当IC卡的电源电压和其他信号从静止状态中复苏且申请复位信号时,IC卡产生的复位. 2)  热复位(Warm Reset) 在时钟(CLK)和电源电压(VCC)处 ...

  10. MIFARE系列8《D8M1.exe》

    软件名:D8M1.exe 更新时间:2014.06.28 操作系统:windowAll 外部设备:D8读卡器 D8M1可以对MIFARE块读写操作,支持1K,4K.检验KEY后返回SAK,QTAQ,U ...