写份DIV2的完整题解

A

判断下HQ9有没有出现过

  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. #define N 112
  12. #define LL long long
  13. #define INF 0xfffffff
  14. const double eps = 1e-;
  15. const double pi = acos(-1.0);
  16. const double inf = ~0u>>;
  17. char s[N];
  18. int main()
  19. {
  20. int i,j,k;
  21. cin>>s;
  22. k = strlen(s);
  23. for(i = ; i < k ;i++)
  24. if(s[i]=='H'||s[i]==''||s[i]=='Q')
  25. break;
  26. if(i==k)
  27. puts("NO");
  28. else
  29. puts("YES");
  30. return ;
  31. }

B

模拟下就OK

  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. #define N 112
  12. #define LL long long
  13. #define INF 0xfffffff
  14. #define mod 1000003
  15. const double eps = 1e-;
  16. const double pi = acos(-1.0);
  17. const double inf = ~0u>>;
  18. char s[N];
  19. int a[];
  20. int main()
  21. {
  22. int i,j,k;
  23. a['>'] = ;
  24. a['<'] = ;
  25. a['+'] = ;
  26. a['-'] = ;
  27. a['.'] = ;
  28. a[','] = ;
  29. a['['] = ;
  30. a[']'] = ;
  31. cin>>s;
  32. k = strlen(s);
  33. int ans = ;
  34. for(i = ;i < k ; i++)
  35. {
  36. // cout<<a[s[i]]<<endl;
  37. ans = (ans*+a[s[i]])%mod;
  38. }
  39. cout<<ans<<endl;
  40. return ;
  41. }

C

题意有点费解 给定操作 使其数字变为字符 先给你字符 问原先数字为多少 模拟。。

  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. #define N 112
  12. #define LL long long
  13. #define INF 0xfffffff
  14. #define mod 256
  15. const double eps = 1e-;
  16. const double pi = acos(-1.0);
  17. const double inf = ~0u>>;
  18. char s[N];
  19. int a[];
  20. int main()
  21. {
  22. int i,j,k;
  23. gets(s);
  24. k = strlen(s);
  25. int ans = ;
  26. int kt = ;
  27. for(i = ;i < k ; i++)
  28. {
  29. int x = s[i];
  30. int y = kt;
  31. int g = ;kt=;
  32. memset(a,,sizeof(a));
  33. while(y)
  34. {
  35. a[g++] = y%;
  36. y/=;
  37. }
  38. for(j = ; j < ;j++)
  39. kt+=pow(,-j-)*a[j];
  40. memset(a,,sizeof(a));
  41. g = ;
  42. while(x)
  43. {
  44. a[g++] = x%;
  45. x/=;
  46. }
  47. int ans = ;
  48. for(j = ; j < ;j++)
  49. ans+=pow(,-j-)*a[j];
  50. kt = (kt-ans+mod)%mod;
  51. cout<<kt<<endl;
  52. kt = s[i];
  53. }
  54. return ;
  55. }

D

题意更是费解 大意:你当前在某一个颜色块中 你有两个指向标  一个是向另一块前进的方向 另一个是在本块的前进方向 0块和边外不能走 问m次后你在哪个块中

模拟。。

  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. #define N 112
  12. #define LL long long
  13. #define INF 0xfffffff
  14. #define mod 256
  15. const double eps = 1e-;
  16. const double pi = acos(-1.0);
  17. const double inf = ~0u>>;
  18. char s[][];
  19. int a[][][],n,k;
  20. int judge(int x,int y)
  21. {
  22. if(x<||x>=n||y<||y>=k)
  23. return ;
  24. if(s[x][y]=='') return ;
  25. return ;
  26. }
  27. int main()
  28. {
  29. int i,j,m,g;
  30. cin>>n>>m;
  31. for(i = ; i < n ;i++)
  32. cin>>s[i];
  33. k = strlen(s[]);
  34. for(i = ;i < n ;i++)
  35. {
  36. for(j = ; j < k ;j++)
  37. {
  38. for(g = j ; g >= ; g--)
  39. if(s[i][g]!=s[i][j]) break;
  40. a[i][j][] = g+;
  41. for(g = i ; g >= ; g--)
  42. if(s[g][j]!=s[i][j]) break;
  43. a[i][j][] = g+;
  44. for(g = j ; g < k; g++)
  45. if(s[i][g]!=s[i][j]) break;
  46. a[i][j][] = g-;
  47. for(g = i ; g < n ;g++)
  48. if(s[g][j]!=s[i][j]) break;
  49. a[i][j][] = g-;
  50. }
  51. }
  52. int d1 = ,d2 = ,x = ,y = ;
  53. char c = s[][];
  54. int k1 = ;
  55. while(k1<=m)
  56. {
  57. if(d1==||d1==)
  58. x = a[x][y][d1];
  59. else y = a[x][y][d1];
  60. if(d2==||d2==)
  61. x = a[x][y][d2];
  62. else y = a[x][y][d2];
  63. int tx,ty;
  64. if(d1==)
  65. {
  66. tx = x-;ty = y;
  67. }
  68. else if(d1==)
  69. {
  70. tx = x;ty = y+;
  71. }
  72. else if(d1==)
  73. {
  74. tx = x+;ty = y;
  75. }
  76. else
  77. {
  78. tx = x;ty = y-;
  79. }
  80. if(!judge(tx,ty))
  81. {
  82. //cout<<",";
  83. if((d2+)%==d1)
  84. d2 = (d1+)%;
  85. else
  86. {
  87.  
  88. d1 = (d1+)%;d2 = (d1-+)%;
  89. }
  90. }
  91. else
  92. {
  93. c = s[tx][ty];
  94. x = tx,y = ty;
  95. }
  96. k1++;
  97. //x = tx
  98. //cout<<c<<" "<<d1<<" "<<d2<<" "<<k1<<" "<<x<<" "<<y<<endl;
  99. }
  100. cout<<c<<endl;
  101. return ;
  102. }

E

当时的思路貌似不太对 按照zp说的思路又重写了一遍

dp[i][j][0] 表示在i位置已经改变了j次方向为正的最大移动距离 dp[i][j][1]类似表反方向。

  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. #define N 112
  12. #define LL long long
  13. #define INF 0xfffffff
  14. #define mod 256
  15. const double eps = 1e-;
  16. const double pi = acos(-1.0);
  17. const double inf = ~0u>>;
  18. int dp[N][][];
  19. char s[N];
  20. int main()
  21. {
  22. int i,j,k;
  23. cin>>s;
  24. cin>>k;
  25. int kk = strlen(s);
  26. for(i = ; i < kk ; i++)
  27. for(j = ; j <= k ; j++)
  28. dp[i][j][] = dp[i][j][] = -INF;
  29. if(s[]=='T')
  30. {
  31. for(i = ; i <= k ; i++)
  32. {
  33. if(i%!=)
  34. dp[][i][] = -;
  35. else
  36. dp[][i][] = ;
  37. }
  38. }
  39. else
  40. {
  41. for(i = ; i <= k ; i++)
  42. if(i%==)
  43. dp[][i][] = ;
  44. else
  45. dp[][i][] = ;
  46. }
  47. for(i = ; i < kk ;i++)
  48. {
  49. if(s[i]=='T')
  50. {
  51. dp[i][][] = dp[i-][][];
  52. dp[i][][] = dp[i-][][];
  53. }
  54. else
  55. {
  56. dp[i][][] = dp[i-][][]+;
  57. dp[i][][] = dp[i-][][]-;
  58. }
  59. for(j = ; j <= k ; j++)
  60. {
  61. if(s[i]=='T')
  62. {
  63. dp[i][j][] = max(dp[i-][j][],dp[i-][j-][]+);
  64. dp[i][j][] = max(dp[i-][j][],dp[i-][j-][]-);
  65. }
  66. else
  67. {
  68. dp[i][j][] = max(dp[i-][j][]+,dp[i-][j-][]);
  69. dp[i][j][] = max(dp[i-][j][]-,dp[i-][j-][]);
  70. }
  71. }
  72. }
  73. int ans1 = max(dp[kk-][k][],dp[kk-][k][]);
  74. for(i = ; i < kk ; i++)
  75. for(j = ; j <= k ; j++)
  76. dp[i][j][] = dp[i][j][] = -INF;
  77. if(s[]=='T')
  78. {
  79. for(i = ; i <= k ; i++)
  80. {
  81. if(i%!=)
  82. dp[][i][] = ;
  83. else
  84. dp[][i][] = ;
  85. }
  86. }
  87. else
  88. {
  89. for(i = ; i <= k ; i++)
  90. if(i%==)
  91. dp[][i][] = -;
  92. else
  93. dp[][i][] = ;
  94. }
  95. for(i = ; i < kk ;i++)
  96. {
  97. if(s[i]=='T')
  98. {
  99. dp[i][][] = dp[i-][][];
  100. dp[i][][] = dp[i-][][];
  101. }
  102. else
  103. {
  104. dp[i][][] = dp[i-][][]+;
  105. dp[i][][] = dp[i-][][]-;
  106. }
  107. for(j = ; j <= k ; j++)
  108. {
  109. if(s[i]=='T')
  110. {
  111. dp[i][j][] = max(dp[i-][j][],dp[i-][j-][]+);
  112. dp[i][j][] = max(dp[i-][j][],dp[i-][j-][]-);
  113. }
  114. else
  115. {
  116. dp[i][j][] = max(dp[i-][j][]+,dp[i-][j-][]);
  117. dp[i][j][] = max(dp[i-][j][]-,dp[i-][j-][]);
  118. }
  119. }
  120. }
  121. int ans2 = max(dp[kk-][k][],dp[kk-][k][]);
  122. //cout<<ans1<<" "<<ans2<<endl;
  123. int ans = max(ans1,ans2);
  124. cout<<ans<<endl;
  125. return ;
  126. }

Codeforces Beta Round #96 (Div. 2) (A-E)的更多相关文章

  1. Codeforces Beta Round #96 (Div. 1) C. Logo Turtle —— DP

    题目链接:http://codeforces.com/contest/132/problem/C C. Logo Turtle time limit per test 2 seconds memory ...

  2. Codeforces Beta Round #96 (Div. 2) E. Logo Turtle dp

    http://codeforces.com/contest/133/problem/E 题目就是给定一段序列,要求那个乌龟要走完整段序列,其中T就是掉头,F就是向前一步,然后开始在原点,起始方向随意, ...

  3. Codeforces Beta Round #96 (Div. 1) D. Constants in the language of Shakespeare 贪心

    D. Constants in the language of Shakespeare Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codef ...

  4. Codeforces Beta Round #96 (Div. 1) C. Logo Turtle DP

    C. Logo Turtle   A lot of people associate Logo programming language with turtle graphics. In this c ...

  5. 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)

    A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

  8. Codeforces Beta Round #69 (Div. 2 Only)

    Codeforces Beta Round #69 (Div. 2 Only) http://codeforces.com/contest/80 A #include<bits/stdc++.h ...

  9. Codeforces Beta Round #40 (Div. 2)

    Codeforces Beta Round #40 (Div. 2) http://codeforces.com/contest/41 A #include<bits/stdc++.h> ...

随机推荐

  1. gbk转utf-8 iconv 编码转换

    linux以下有时候 字符须要进行编码转换(爬虫将gbk转为utf-8编码...).一般能够选择iconv函数. 终端以下  输入 man 3 iconv 得到  iconv函数的用法. 个人看习惯了 ...

  2. OTG识别原理

    如图1所示,那个是Micro USB的母头,可以清晰看到有5pin,分别是(不分顺序):Vbus.GND.D+.D-.ID.当移动设备,类似手机.平板电脑等要支持OTG功能,就必须使用这个接口,而且电 ...

  3. Qt实现一个简单的TextEditor

    使用QT实现简单的TextEditor: 首先在窗口添加部件TextEditor,并设置中文字符 MainWindow::MainWindow(QWidget *parent) : QMainWind ...

  4. udhcp源码详解(三)上 之配置信息的读取

    上节介绍了存储管理配置信息的结构体struct server_config_t,该结构体贯穿整个server端程序的运行. 在dhcpd.c里的用该结构体定义个一个全局的变量: struct serv ...

  5. IIS+Asp.Net Mvc必须知道的事(解决启动/重启/自动回收站点后第一次访问慢问题)

    问题现象: Asp.net Mvc站点部署在IIS上后,第一个用户第一次访问站点,都会比较慢,确切的说是访问站点的Action页面(即非静态页面,因为静态页面直接由IIS处理返回给用户即完成请求,而A ...

  6. 我的kindle书单

    刚刚入手kindle,希望能够持续阅读,不断进步. 列下书单,记录我的阅读足迹,更希望园友若有好书多多推荐,互相交流. # keep updating ... 我的kindle书单 book name ...

  7. Android 4.4.2 动态加入JNI库方法记录 (二 app应用层)

    欢迎转载,务必注明出处:http://blog.csdn.net/wang_shuai_ww/article/details/44458553 源代码下载地址:http://download.csdn ...

  8. Spring中AOP的使用

    问题:什么是AOP? 答:AOP基本概念:Aspect-Oriented Programming,面向方面编程的简称,Aspect是一种新的模块化机制.用来描写叙述分散在对象.类或方法中的横切关注点( ...

  9. Bean Query 第一个版本号(1.0.0)已公布

    BeanQuery 是一个把对象转换为Map的Java工具库. 支持选择Bean中的一些属性.对结果进行排序和依照条件查询. 不只能够作用于顶层对象,也能够作用于子对象.很多其它具体的介绍能够看我的博 ...

  10. asp.net项目与开源单点登录项目CAS的结合

    这段时间搞的一个asp.net mvc项目,采用了单点登录. 这个单点登录就是CAS,一个开源的JAVA项目.当然,这并不影响ASP.NET项目结合它来进行登录.因为各自分工不同:单点登录(管它是不是 ...