水 A - Alena's Schedule

  1. /************************************************
  2. * Author :Running_Time
  3. * Created Time :2015/10/12 星期一 16:49:42
  4. * File Name :A.cpp
  5. ************************************************/
  6.  
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <iostream>
  10. #include <sstream>
  11. #include <cstring>
  12. #include <cmath>
  13. #include <string>
  14. #include <vector>
  15. #include <queue>
  16. #include <deque>
  17. #include <stack>
  18. #include <list>
  19. #include <map>
  20. #include <set>
  21. #include <bitset>
  22. #include <cstdlib>
  23. #include <ctime>
  24. using namespace std;
  25.  
  26. #define lson l, mid, rt << 1
  27. #define rson mid + 1, r, rt << 1 | 1
  28. typedef long long ll;
  29. const int N = 1e2 + 10;
  30. const int INF = 0x3f3f3f3f;
  31. const int MOD = 1e9 + 7;
  32. const double EPS = 1e-8;
  33. int a[N];
  34.  
  35. int main(void) {
  36. int n; scanf ("%d", &n);
  37. for (int i=1; i<=n; ++i) {
  38. scanf ("%d", &a[i]);
  39. }
  40. int ans = 0, i = 1;
  41. bool fir = true;
  42. while (i <= n) {
  43. if (a[i] == 0) {
  44. if (fir) {
  45. i++; continue;
  46. }
  47. else {
  48. int j = i + 1;
  49. while (j <= n) {
  50. if (a[j] == 0) {
  51. j++;
  52. }
  53. else break;
  54. }
  55. if (j == n + 1) break;
  56. if (j - i >= 2) {
  57. i = j; continue;
  58. }
  59. else {
  60. ans += j - i;
  61. i = j;
  62. }
  63. }
  64. }
  65. else { //a[i] = 1;
  66. fir = false;
  67. ans++; i++;
  68. }
  69. }
  70. printf ("%d\n", ans);
  71.  
  72. return 0;
  73. }

  

水 B - Laurenty and Shop

  1. /************************************************
  2. * Author :Running_Time
  3. * Created Time :2015/10/12 星期一 16:49:42
  4. * File Name :B.cpp
  5. ************************************************/
  6.  
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <iostream>
  10. #include <sstream>
  11. #include <cstring>
  12. #include <cmath>
  13. #include <string>
  14. #include <vector>
  15. #include <queue>
  16. #include <deque>
  17. #include <stack>
  18. #include <list>
  19. #include <map>
  20. #include <set>
  21. #include <bitset>
  22. #include <cstdlib>
  23. #include <ctime>
  24. using namespace std;
  25.  
  26. #define lson l, mid, rt << 1
  27. #define rson mid + 1, r, rt << 1 | 1
  28. typedef long long ll;
  29. const int N = 55;
  30. const int INF = 0x3f3f3f3f;
  31. const int MOD = 1e9 + 7;
  32. const double EPS = 1e-8;
  33. int a1[N], a2[N], b[N];
  34. int sum1[N], sum2[N];
  35. bool vis[N];
  36.  
  37. int main(void) {
  38. int n; scanf ("%d", &n);
  39. for (int i=1; i<n; ++i) {
  40. scanf ("%d", &a1[i]);
  41. }
  42. for (int i=1; i<n; ++i) {
  43. scanf ("%d", &a2[i]);
  44. }
  45. for (int i=1; i<=n; ++i) {
  46. scanf ("%d", &b[i]);
  47. }
  48.  
  49. if (n == 2) {
  50. printf ("%d\n", a1[1] + a2[1] + b[1] + b[2]);
  51. return 0;
  52. }
  53.  
  54. for (int i=1; i<n; ++i) {
  55. sum1[i] = sum1[i-1] + a1[i];
  56. }
  57. for (int i=n-1; i>=1; --i) {
  58. sum2[i] = sum2[i+1] + a2[i];
  59. }
  60. int mn = INF, id = 0;
  61. int ans = 0;
  62. for (int i=0; i<n; ++i) {
  63. if (sum1[i] + b[i+1] + sum2[i+1] < mn) {
  64. mn = sum1[i] + b[i+1] + sum2[i+1];
  65. id = i;
  66. }
  67. }
  68. vis[id] = true; ans += mn;
  69. mn = INF, id = 0;
  70. for (int i=0; i<n; ++i) {
  71. if (sum1[i] + b[i+1] + sum2[i+1] < mn && !vis[i]) {
  72. mn = sum1[i] + b[i+1] + sum2[i+1];
  73. id = i;
  74. }
  75. }
  76. ans += mn;
  77. printf ("%d\n", ans);
  78.  
  79. return 0;
  80. }

  

暴力+队列 C - Gennady the Dentist

题意:小孩子排队看医生,有一定的连锁反应,问医生最后能治好多少人

分析:开始想用D保存d[]的和,无奈被hack掉了,还是老老实实用队列吧

  1. /************************************************
  2. * Author :Running_Time
  3. * Created Time :2015/10/12 星期一 16:49:42
  4. * File Name :C.cpp
  5. ************************************************/
  6.  
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <iostream>
  10. #include <sstream>
  11. #include <cstring>
  12. #include <cmath>
  13. #include <string>
  14. #include <vector>
  15. #include <queue>
  16. #include <deque>
  17. #include <stack>
  18. #include <list>
  19. #include <map>
  20. #include <set>
  21. #include <bitset>
  22. #include <cstdlib>
  23. #include <ctime>
  24. using namespace std;
  25.  
  26. #define lson l, mid, rt << 1
  27. #define rson mid + 1, r, rt << 1 | 1
  28. typedef long long ll;
  29. const int N = 4e3 + 10;
  30. const int INF = 0x3f3f3f3f;
  31. const int MOD = 1e9 + 7;
  32. const double EPS = 1e-8;
  33. int v[N], d[N], p[N];
  34. bool dead[N];
  35.  
  36. int main(void) {
  37. int n; scanf ("%d", &n);
  38. for (int i=1; i<=n; ++i) {
  39. scanf ("%d%d%d", &v[i], &d[i], &p[i]);
  40. dead[i] = false;
  41. }
  42. vector<int> ans;
  43. queue<int> Q;
  44. for (int i=1; i<=n; ++i) {
  45. if (!dead[i]) {
  46. ans.push_back (i);
  47. for (int j=i+1; j<=n; ++j) {
  48. if (dead[j]) continue;
  49. p[j] -= v[i]; v[i]--;
  50. if (p[j] < 0) {
  51. dead[j] = true;
  52. Q.push (j);
  53. }
  54. if (v[i] <= 0) break;
  55. }
  56. }
  57. while (!Q.empty ()) {
  58. int x = Q.front (); Q.pop ();
  59. for (int j=x+1; j<=n; ++j) {
  60. if (dead[j]) continue;
  61. p[j] -= d[x];
  62. if (p[j] < 0) {
  63. dead[j] = true;
  64. Q.push (j);
  65. }
  66. }
  67. }
  68. }
  69.  
  70. printf ("%d\n", ans.size ());
  71. for (int i=0; i<ans.size (); ++i) {
  72. printf ("%d%c", ans[i], i == ans.size () - 1 ? '\n' : ' ');
  73. }
  74.  
  75. return 0;
  76. }

  

BFS D - Phillip and Trains

题意:一个人从左边走到右边,同时有列车从右边开过来,问这个人能否达到右边没有碰到列车

分析:简答的BFS,车看作不动,人相对车有一个相对运动,还是要用vis标记已访问过的点,比赛时这点忘了,MLE了

  1. /************************************************
  2. * Author :Running_Time
  3. * Created Time :2015/10/12 星期一 16:49:42
  4. * File Name :D.cpp
  5. ************************************************/
  6.  
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <iostream>
  10. #include <sstream>
  11. #include <cstring>
  12. #include <cmath>
  13. #include <string>
  14. #include <vector>
  15. #include <queue>
  16. #include <deque>
  17. #include <stack>
  18. #include <list>
  19. #include <map>
  20. #include <set>
  21. #include <bitset>
  22. #include <cstdlib>
  23. #include <ctime>
  24. using namespace std;
  25.  
  26. #define lson l, mid, rt << 1
  27. #define rson mid + 1, r, rt << 1 | 1
  28. typedef long long ll;
  29. const int N = 1e2 + 10;
  30. const int INF = 0x3f3f3f3f;
  31. const int MOD = 1e9 + 7;
  32. const double EPS = 1e-8;
  33. char maze[4][N];
  34. bool vis[4][N];
  35. int dx[3] = {-1, 0, 1};
  36. int n, k;
  37.  
  38. bool BFS(int sx, int sy) {
  39. queue<pair<int, int> > Q; Q.push (make_pair (sx, sy));
  40. memset (vis, false, sizeof (vis)); vis[sx][sy] = true;
  41. while (!Q.empty ()) {
  42. int x = Q.front ().first, y = Q.front ().second; Q.pop ();
  43. if (y >= n) return true;
  44. if (y + 1 <= n && maze[x][y+1] != '.') continue;
  45. for (int i=0; i<3; ++i) {
  46. int tx = x + dx[i], ty = y + 1;
  47. if (tx < 1 || tx > 3 || maze[tx][ty] != '.') continue;
  48. ty += 1;
  49. if (ty <= n && maze[tx][ty] != '.') continue;
  50. ty += 1;
  51. if (ty <= n && maze[tx][ty] != '.') continue;
  52. if (vis[tx][ty]) continue;
  53. vis[tx][ty] = true;
  54. Q.push (make_pair (tx, ty));
  55. }
  56. }
  57. return false;
  58. }
  59.  
  60. int main(void) {
  61. int T; scanf ("%d", &T);
  62. while (T--) {
  63. scanf ("%d%d", &n, &k);
  64. for (int i=1; i<=3; ++i) {
  65. scanf ("%s", maze[i] + 1);
  66. }
  67. int sx = 0, sy = 0;
  68. for (int i=1; i<=3; ++i) {
  69. if (maze[i][1] == 's') {
  70. sx = i; sy = 1;
  71. break;
  72. }
  73. }
  74. for (int i=n+1; i<=n+6; ++i) {
  75. maze[1][i] = maze[2][i] = maze[3][i] = '.';
  76. }
  77. printf ("%s\n", BFS (sx, sy) ? "YES" : "NO");
  78. }
  79.  
  80. return 0;
  81. }

  

Codeforces Round #325 (Div. 2)的更多相关文章

  1. Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid

    F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  2. Codeforces Round #325 (Div. 2) D. Phillip and Trains BFS

    D. Phillip and Trains Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/ ...

  3. Codeforces Round #325 (Div. 2) C. Gennady the Dentist 暴力

    C. Gennady the Dentist Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586 ...

  4. Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题

    A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/pr ...

  5. Codeforces Round #325 (Div. 2) B. Laurenty and Shop 前缀和

    B. Laurenty and Shop Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/p ...

  6. Codeforces Round #325 (Div. 2) Phillip and Trains dp

    原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. ...

  7. Codeforces Round #325 (Div. 2) Laurenty and Shop 模拟

    原题链接:http://codeforces.com/contest/586/problem/B 题意: 大概就是给你一个两行的路,让你寻找一个来回的最短路,并且不能走重复的路. 题解: 就枚举上下选 ...

  8. Codeforces Round #325 (Div. 2) Alena's Schedule 模拟

    原题链接:http://codeforces.com/contest/586/problem/A 题意: 大概就是给你个序列..瞎比让你统计统计什么长度 题解: 就瞎比搞搞就好 代码: #includ ...

  9. Codeforces Round #325 (Div. 2) D bfs

    D. Phillip and Trains time limit per test 1 second memory limit per test 256 megabytes input standar ...

  10. Codeforces Round #325 (Div. 1) D. Lizard Era: Beginning

    折半搜索,先搜索一半的数字,记录第一个人的值,第二个人.第三个人和第一个人的差值,开个map哈希存一下,然后另一半搜完直接根据差值查找前一半的答案. 代码 #include<cstdio> ...

随机推荐

  1. mysql 查询正在执行的事务以及等待锁 常用的sql语句

    使用navicat测试学习: 首先使用set autocommit = 0;(取消自动提交,则当执行语句commit或者rollback执行提交事务或者回滚)   在打开一个执行update查询 正在 ...

  2. struct与 union的基本用法

    结构体与联合体是C语言的常见数据类型,可对C的基本数据类型进行组合使之能表示复杂的数据结构,意义深远,是优异代码的必备工具.一.        struct与 union的基本用法,在语法上union ...

  3. Git使用之Permission Denied问题解决

    今天碰到了Git的Permission Denied问题. 在安装好git之后,我们通常会配置username和邮箱 git config --global user.name "zengj ...

  4. Mac版的idea部分按钮失效的解决方案

    问题描述:调整了一下idea中jdk的路径,之后idea就无法打开新项目了,最好发现idea中的顶部菜单全部失效 解决过程: 1.把idea的jdk的路径调回去,无效 2.重启idea,无效 3.重启 ...

  5. monitor and move the log content to our big data system

    Apache Flume HDFS Sink Tutorial | HowToProgram https://howtoprogram.xyz/2016/08/01/apache-flume-hdfs ...

  6. URAL 1731. Dill(数学啊 )

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1731 1731. Dill Time limit: 0.5 second Memory ...

  7. Unity3D集成腾讯语音GVoice SDK

    友情提示:最近发现腾讯GVoice有另一个官网,叫做腾讯游戏服务,经过对比发现这个网站才是最新的,下面我介绍的那个估计是已经废弃的,但不知道为啥老的网站没有直接链接到新网址而是仍然保留了.不过新官网的 ...

  8. hihocoder #1068 : RMQ-ST算法 ( RMQ算法 O(nlogn)处理 O(1)查询 *【模板】 1)初始化d数组直接读入+计算k值用数学函数log2()==*节约时间 )

    #1068 : RMQ-ST算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在美国旅行了相当长的一段时间之后,终于准备要回国啦!而在回国之前,他们准备 ...

  9. 关于苹果iPhone手机对页面margin属性无效的解决方法一(如有错误,请留言批评)

    这个问题,是在给商城网站底部footer设置margin属性的时候发现的,先把出现问题的截图发出来看一下 ​安卓手机,打开正常 ​iphone6 p 打开出现的问题(无视margin-bottom:6 ...

  10. poj 3368 Frequent values 解题报告

    题目链接:http://poj.org/problem?id=3368 题目意思:给出一段 n 个数的序列你,对于区间 [l, r] 的询问,找出 出现频率最高的数的次数.考虑到序列中的数是非递减的, ...