Codeforces Round #325 (Div. 2)
- /************************************************
- * Author :Running_Time
- * Created Time :2015/10/12 星期一 16:49:42
- * File Name :A.cpp
- ************************************************/
- #include <cstdio>
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <cstring>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <queue>
- #include <deque>
- #include <stack>
- #include <list>
- #include <map>
- #include <set>
- #include <bitset>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- #define lson l, mid, rt << 1
- #define rson mid + 1, r, rt << 1 | 1
- typedef long long ll;
- const int N = 1e2 + 10;
- const int INF = 0x3f3f3f3f;
- const int MOD = 1e9 + 7;
- const double EPS = 1e-8;
- int a[N];
- int main(void) {
- int n; scanf ("%d", &n);
- for (int i=1; i<=n; ++i) {
- scanf ("%d", &a[i]);
- }
- int ans = 0, i = 1;
- bool fir = true;
- while (i <= n) {
- if (a[i] == 0) {
- if (fir) {
- i++; continue;
- }
- else {
- int j = i + 1;
- while (j <= n) {
- if (a[j] == 0) {
- j++;
- }
- else break;
- }
- if (j == n + 1) break;
- if (j - i >= 2) {
- i = j; continue;
- }
- else {
- ans += j - i;
- i = j;
- }
- }
- }
- else { //a[i] = 1;
- fir = false;
- ans++; i++;
- }
- }
- printf ("%d\n", ans);
- return 0;
- }
- /************************************************
- * Author :Running_Time
- * Created Time :2015/10/12 星期一 16:49:42
- * File Name :B.cpp
- ************************************************/
- #include <cstdio>
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <cstring>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <queue>
- #include <deque>
- #include <stack>
- #include <list>
- #include <map>
- #include <set>
- #include <bitset>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- #define lson l, mid, rt << 1
- #define rson mid + 1, r, rt << 1 | 1
- typedef long long ll;
- const int N = 55;
- const int INF = 0x3f3f3f3f;
- const int MOD = 1e9 + 7;
- const double EPS = 1e-8;
- int a1[N], a2[N], b[N];
- int sum1[N], sum2[N];
- bool vis[N];
- int main(void) {
- int n; scanf ("%d", &n);
- for (int i=1; i<n; ++i) {
- scanf ("%d", &a1[i]);
- }
- for (int i=1; i<n; ++i) {
- scanf ("%d", &a2[i]);
- }
- for (int i=1; i<=n; ++i) {
- scanf ("%d", &b[i]);
- }
- if (n == 2) {
- printf ("%d\n", a1[1] + a2[1] + b[1] + b[2]);
- return 0;
- }
- for (int i=1; i<n; ++i) {
- sum1[i] = sum1[i-1] + a1[i];
- }
- for (int i=n-1; i>=1; --i) {
- sum2[i] = sum2[i+1] + a2[i];
- }
- int mn = INF, id = 0;
- int ans = 0;
- for (int i=0; i<n; ++i) {
- if (sum1[i] + b[i+1] + sum2[i+1] < mn) {
- mn = sum1[i] + b[i+1] + sum2[i+1];
- id = i;
- }
- }
- vis[id] = true; ans += mn;
- mn = INF, id = 0;
- for (int i=0; i<n; ++i) {
- if (sum1[i] + b[i+1] + sum2[i+1] < mn && !vis[i]) {
- mn = sum1[i] + b[i+1] + sum2[i+1];
- id = i;
- }
- }
- ans += mn;
- printf ("%d\n", ans);
- return 0;
- }
暴力+队列 C - Gennady the Dentist
题意:小孩子排队看医生,有一定的连锁反应,问医生最后能治好多少人
分析:开始想用D保存d[]的和,无奈被hack掉了,还是老老实实用队列吧
- /************************************************
- * Author :Running_Time
- * Created Time :2015/10/12 星期一 16:49:42
- * File Name :C.cpp
- ************************************************/
- #include <cstdio>
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <cstring>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <queue>
- #include <deque>
- #include <stack>
- #include <list>
- #include <map>
- #include <set>
- #include <bitset>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- #define lson l, mid, rt << 1
- #define rson mid + 1, r, rt << 1 | 1
- typedef long long ll;
- const int N = 4e3 + 10;
- const int INF = 0x3f3f3f3f;
- const int MOD = 1e9 + 7;
- const double EPS = 1e-8;
- int v[N], d[N], p[N];
- bool dead[N];
- int main(void) {
- int n; scanf ("%d", &n);
- for (int i=1; i<=n; ++i) {
- scanf ("%d%d%d", &v[i], &d[i], &p[i]);
- dead[i] = false;
- }
- vector<int> ans;
- queue<int> Q;
- for (int i=1; i<=n; ++i) {
- if (!dead[i]) {
- ans.push_back (i);
- for (int j=i+1; j<=n; ++j) {
- if (dead[j]) continue;
- p[j] -= v[i]; v[i]--;
- if (p[j] < 0) {
- dead[j] = true;
- Q.push (j);
- }
- if (v[i] <= 0) break;
- }
- }
- while (!Q.empty ()) {
- int x = Q.front (); Q.pop ();
- for (int j=x+1; j<=n; ++j) {
- if (dead[j]) continue;
- p[j] -= d[x];
- if (p[j] < 0) {
- dead[j] = true;
- Q.push (j);
- }
- }
- }
- }
- printf ("%d\n", ans.size ());
- for (int i=0; i<ans.size (); ++i) {
- printf ("%d%c", ans[i], i == ans.size () - 1 ? '\n' : ' ');
- }
- return 0;
- }
题意:一个人从左边走到右边,同时有列车从右边开过来,问这个人能否达到右边没有碰到列车
分析:简答的BFS,车看作不动,人相对车有一个相对运动,还是要用vis标记已访问过的点,比赛时这点忘了,MLE了
- /************************************************
- * Author :Running_Time
- * Created Time :2015/10/12 星期一 16:49:42
- * File Name :D.cpp
- ************************************************/
- #include <cstdio>
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <cstring>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <queue>
- #include <deque>
- #include <stack>
- #include <list>
- #include <map>
- #include <set>
- #include <bitset>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- #define lson l, mid, rt << 1
- #define rson mid + 1, r, rt << 1 | 1
- typedef long long ll;
- const int N = 1e2 + 10;
- const int INF = 0x3f3f3f3f;
- const int MOD = 1e9 + 7;
- const double EPS = 1e-8;
- char maze[4][N];
- bool vis[4][N];
- int dx[3] = {-1, 0, 1};
- int n, k;
- bool BFS(int sx, int sy) {
- queue<pair<int, int> > Q; Q.push (make_pair (sx, sy));
- memset (vis, false, sizeof (vis)); vis[sx][sy] = true;
- while (!Q.empty ()) {
- int x = Q.front ().first, y = Q.front ().second; Q.pop ();
- if (y >= n) return true;
- if (y + 1 <= n && maze[x][y+1] != '.') continue;
- for (int i=0; i<3; ++i) {
- int tx = x + dx[i], ty = y + 1;
- if (tx < 1 || tx > 3 || maze[tx][ty] != '.') continue;
- ty += 1;
- if (ty <= n && maze[tx][ty] != '.') continue;
- ty += 1;
- if (ty <= n && maze[tx][ty] != '.') continue;
- if (vis[tx][ty]) continue;
- vis[tx][ty] = true;
- Q.push (make_pair (tx, ty));
- }
- }
- return false;
- }
- int main(void) {
- int T; scanf ("%d", &T);
- while (T--) {
- scanf ("%d%d", &n, &k);
- for (int i=1; i<=3; ++i) {
- scanf ("%s", maze[i] + 1);
- }
- int sx = 0, sy = 0;
- for (int i=1; i<=3; ++i) {
- if (maze[i][1] == 's') {
- sx = i; sy = 1;
- break;
- }
- }
- for (int i=n+1; i<=n+6; ++i) {
- maze[1][i] = maze[2][i] = maze[3][i] = '.';
- }
- printf ("%s\n", BFS (sx, sy) ? "YES" : "NO");
- }
- return 0;
- }
Codeforces Round #325 (Div. 2)的更多相关文章
- 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 ...
- 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/ ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #325 (Div. 2) Phillip and Trains dp
原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. ...
- Codeforces Round #325 (Div. 2) Laurenty and Shop 模拟
原题链接:http://codeforces.com/contest/586/problem/B 题意: 大概就是给你一个两行的路,让你寻找一个来回的最短路,并且不能走重复的路. 题解: 就枚举上下选 ...
- Codeforces Round #325 (Div. 2) Alena's Schedule 模拟
原题链接:http://codeforces.com/contest/586/problem/A 题意: 大概就是给你个序列..瞎比让你统计统计什么长度 题解: 就瞎比搞搞就好 代码: #includ ...
- 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 ...
- Codeforces Round #325 (Div. 1) D. Lizard Era: Beginning
折半搜索,先搜索一半的数字,记录第一个人的值,第二个人.第三个人和第一个人的差值,开个map哈希存一下,然后另一半搜完直接根据差值查找前一半的答案. 代码 #include<cstdio> ...
随机推荐
- mysql 查询正在执行的事务以及等待锁 常用的sql语句
使用navicat测试学习: 首先使用set autocommit = 0;(取消自动提交,则当执行语句commit或者rollback执行提交事务或者回滚) 在打开一个执行update查询 正在 ...
- struct与 union的基本用法
结构体与联合体是C语言的常见数据类型,可对C的基本数据类型进行组合使之能表示复杂的数据结构,意义深远,是优异代码的必备工具.一. struct与 union的基本用法,在语法上union ...
- Git使用之Permission Denied问题解决
今天碰到了Git的Permission Denied问题. 在安装好git之后,我们通常会配置username和邮箱 git config --global user.name "zengj ...
- Mac版的idea部分按钮失效的解决方案
问题描述:调整了一下idea中jdk的路径,之后idea就无法打开新项目了,最好发现idea中的顶部菜单全部失效 解决过程: 1.把idea的jdk的路径调回去,无效 2.重启idea,无效 3.重启 ...
- 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 ...
- URAL 1731. Dill(数学啊 )
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1731 1731. Dill Time limit: 0.5 second Memory ...
- Unity3D集成腾讯语音GVoice SDK
友情提示:最近发现腾讯GVoice有另一个官网,叫做腾讯游戏服务,经过对比发现这个网站才是最新的,下面我介绍的那个估计是已经废弃的,但不知道为啥老的网站没有直接链接到新网址而是仍然保留了.不过新官网的 ...
- hihocoder #1068 : RMQ-ST算法 ( RMQ算法 O(nlogn)处理 O(1)查询 *【模板】 1)初始化d数组直接读入+计算k值用数学函数log2()==*节约时间 )
#1068 : RMQ-ST算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在美国旅行了相当长的一段时间之后,终于准备要回国啦!而在回国之前,他们准备 ...
- 关于苹果iPhone手机对页面margin属性无效的解决方法一(如有错误,请留言批评)
这个问题,是在给商城网站底部footer设置margin属性的时候发现的,先把出现问题的截图发出来看一下 安卓手机,打开正常 iphone6 p 打开出现的问题(无视margin-bottom:6 ...
- poj 3368 Frequent values 解题报告
题目链接:http://poj.org/problem?id=3368 题目意思:给出一段 n 个数的序列你,对于区间 [l, r] 的询问,找出 出现频率最高的数的次数.考虑到序列中的数是非递减的, ...