水 A - Alena's Schedule

/************************************************
* 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;
}

  

水 B - Laurenty and Shop

/************************************************
* 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 D - Phillip and Trains

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

分析:简答的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)的更多相关文章

  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. 用NHibernate处理带属性的多对多关系

    1.引言 老谭在面试开发者的时候,为了考察他们的数据库开发能力,经常祭出我的法宝,就是大学数据库教程中讲到的一个模式:学生选课.这个模式是这种: 在这个模式中,学生(Student)和课程(Cours ...

  2. Hadoop提供的reduce函数中Iterable 接口只能遍历一次的问题

    今天在写MapReduce中的reduce函数时,碰到个问题,特此记录一下: void reduce(key, Iterable<*>values,...) { for(* v:value ...

  3. ssh原理【转】

    1 转自 http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html 2 ssh远程登陆的原理 普通用户远程登陆 ssh jason@ho ...

  4. java sleep和wait的区别和联系

    Thread.sleep不会改变锁的行为,如果当前线程拥有锁,那么当前线程sleep之后,该锁不会被释放. Thread.sleep和Object.wait都会暂停当前的线程,让出cpu.Thread ...

  5. 二阶段 三阶段 提交 Paxos

    关于分布式事务.两阶段提交协议.三阶提交协议 - 文章 - 伯乐在线 http://blog.jobbole.com/95632/

  6. jQuery 怎么获取对象

    1.JQuery的核心的一些方法 each(callback) '就像循环 $("Element").length; ‘元素的个数,是个属性 $("Element&quo ...

  7. FPU同步(翻译)

    本篇翻译的原英文在:http://mauve.mizuumi.net/2013/06/16/desyncs-and-fpu-synchronization/#more-725(可能要FQ) 如果你曾经 ...

  8. 「LuoguT36048」 Storm in Lover

    Description 平成二十四年(2012年),5月11日,东京,某弓道场. "呐,呐,海未酱,你听说了吗?几天后的那场弓道大会?啊-!"橙发少女兴奋地拿着一张传单一样的纸跑向 ...

  9. 【POJ 3461】 Oulipo

    [题目链接] 点击打开链接 [算法] KMP [代码] #include <algorithm> #include <bitset> #include <cctype&g ...

  10. Dijkstra再理解+最短路计数

    众所周知,Dijkstra算法是跑单源最短路的一种优秀算法,不过他的缺点在于难以处理负权边. 但是由于在今年的NOI赛场上SPFA那啥了(嗯就是那啥了),所以我们还是好好研究一下Dij的原理和它的优化 ...