Round #3
题源:感谢 by hzwer
水灾(sliker.cpp/c/pas) 1000MS 64MB
大雨应经下了几天雨,却还是没有停的样子。土豪CCY刚从外地赚完1e元回来,知道不久除了自己别墅,其他的地方都将会被洪水淹没。
CCY所在的城市可以用一个N*M(N,M<=50)的地图表示,地图上有五种符号:“. * X D S”。其中“X”表示石头,水和人都不能从上面经过。“.”表示平原,CCY和洪水都可以经过。“*”表示洪水开始地方(可能有多个地方开始发生洪水)。“D”表示CCY的别墅。“S”表示CCY现在的位置。
CCY每分钟可以向相邻位置移动,而洪水将会在CCY移动之后把相邻的没有的土地淹没(从已淹没的土地)。
求CCY回到别墅的最少时间。如果聪哥回不了家,就很可能会被淹死,那么他就要膜拜黄金大神涨RP来呼叫直升飞机,所以输出“ORZ hzwer!!!”。
输入文件 sliker.in
输出文件 sliker.out
Input
3 3
D.*
…
.S.
Output
3
Input
3 3
D.*
.....S
Output
ORZ hzwer!!!
Input
3 6
D...*.
.X.X..
....S.
Output
6
最短路问题,而且也是经典的BFS题目,但是增加了一个限制”洪水“,而洪水的影响则是在t时刻之后淹没位置(x,y),而我要路过这个位置,则要在t时刻之前路过;
那么可以这样解决,先BFS求出洪水淹没(x,y)所需要的时间t,再BFS求我能否从起始点抵达城堡,对于每抵达的一个点(x,y)要符合几个条件:
1.不能是石头”X“
2.不能超过边界,即1<=x<=n&&1<=y<=m
3.当前时刻这地方还没被洪水淹没,即我抵达的时间T<=t(洪水淹没(x,y)的时间)
那么这题就很愉快的解决了,以下是代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<utility>
#include<numeric>
#include<iterator>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cassert>
using std::cin;
using std::cout;
using std::endl;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
#define FOR(i,init,len) for(int i=(init);i<(len);++i)
#define For(i,init,len) for(int i=(init);i<=(len);++i)
#define fi first
#define se second
#define pb push_back
#define is insert
namespace IO {
inline char getchar() {
static const int BUFSIZE=;
static char buf[BUFSIZE],*begin,*end;
if(begin==end) {
begin=buf;
end=buf+fread(buf,,BUFSIZE,stdin);
if(begin==end) return -;
}
return *begin++;
}
}
inline void read(int &in) {
int c,symbol=;
while(isspace(c=IO::getchar()));
if(c=='-') { in=;symbol=-; }
else in=c-'';
while(isdigit(c=IO::getchar())) { in*=;in+=c-''; }
in*=symbol;
}
inline int read() { static int x;read(x);return x; }
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
#define PA(name,init,len) cout<<#name"["<<(len-init)<<"]=";FOR(_,init,len) cout<<name[_]<<" \n"[_==(len-1)];
#define Pa(name,init,len) cout<<#name"["<<(len-init+1)<<"]=";For(_,init,len) cout<<name[_]<<" \n"[_==(len)];
#define PV(name) cout<<#name"="<<name<<'\n'; const int maxn=;
int n,m;
int dist[maxn][maxn];
bool vis[maxn][maxn];
char s[maxn][maxn]; const int dx[]={,,,-};
const int dy[]={,,-,}; struct Node{
int x,y,time;
Node(int x=,int y=,int time=):x(x),y(y),time(time){}
}; //主要检查坐标是否越界和是否来过
inline bool check(int x,int y){return x>=&&x<=n&&y>=&&y<=m&&!vis[x][y];} //bfs求洪水在什么时候淹没(x,y),那么我必须在洪水淹没之前抵达这里,否则我将不能抵达这里
void flood_bfs(){
std::queue<Node> q;
For(i,,n) For(j,,m) if(s[i][j]=='*') q.push(Node(i,j,)),vis[i][j]=true;
memset(dist,0x3f,sizeof(dist));//初始距离赋值为最大值,按字节赋值0x3f,结果为dist[i][j]=0x3f3f3f3f=1061109567
while(!q.empty()){
Node t=q.front();q.pop();
dist[t.x][t.y]=t.time;
FOR(i,,){
int x=t.x+dx[i],y=t.y+dy[i];
if(check(x,y)&&s[x][y]!='X'&&s[x][y]!='D') q.push(Node(x,y,t.time+)),vis[x][y]=true;
}
}
} //bfs求我抵达城堡的最短时间,如果不能抵达,返回-1
int bfs(){
std::queue<Node> q;
memset(vis,,sizeof(vis));
For(i,,n) For(j,,m) if(s[i][j]=='S') q.push(Node(i,j,)),vis[i][j]=true;
while(!q.empty()){
Node t=q.front();q.pop();
if(s[t.x][t.y]=='D') return t.time;
FOR(i,,){
int x=t.x+dx[i],y=t.y+dy[i];
if(check(x,y)&&s[x][y]!='X'&&t.time+<dist[x][y]) q.push(Node(x,y,t.time+)),vis[x][y]=true;
}
}
return -;
} int main() {
#ifdef MengLan
int Beginning=clock();
//freopen("in","r",stdin);
//freopen("out","w",stdout);
#endif // MengLan scanf("%d%d",&n,&m);
For(i,,n) scanf("%s",s[i]+);
flood_bfs();
int ans=bfs();
if(ans==-) puts("ORZ hzwer!!!");
else printf("%d\n",ans); #ifdef MengLan
printf("Time: %d\n",clock()-Beginning);
system("pause");
#endif // MengLan
return ;
}
某种数列问题 (jx.cpp/c/pas) 1000MS 256MB
众所周知,chenzeyu97有无数的妹子(阿掉!>_<),而且他还有很多恶趣味的问题,继上次纠结于一排妹子的排法以后,今天他有非(chi)常(bao)认(cheng)真(zhe)去研究一个奇怪的问题。有一堆他的妹子站成一排,然后对于每个妹子有一个美丽度,当然美丽度越大越好,chenzeyu97妹子很多,但是质量上不容乐观,经常出现很多美丽度为负数的妹子(喜闻乐见),chenzeyu97希望从一排妹子里找出3队连续的妹子,使她们的美丽度和最大。注意,一个妹子不能被编入多个队伍而且一定要拿出三队,不然czy会闲着没事做~。
简单滴说就是:
给定一个数列,从中找到3个无交集的连续子数列使其和最大。
【输入文件】
第一行一个数n,表示数列长度。
接下来有n行,每行一个数,第i行为第i个数。
【输出文件】
仅有一个数,表示最大和。
【样例输入】 jx.in
10
-1
2
3
-4
0
1
-6
-1
1
-2
【样例输出】 jx.out
7
【样例说明】
第一队妹子取2,3。
第二队妹子取0,1。
第三队妹子取1。
【数据范围】
请大家放心,虽然chenzeyu97妹子无数,但是这次他叫来的个数n是有限的。=v=
对于30%的数据,妹子数不大于200。
对于60%的数据,妹子数不大于2000。
对于100%的数据,妹子数1000000。
而且,由于chenzeyu97没有CCR那样的影响力,所以他的妹子选完的最大美丽度和不超过maxlongint。(注:CCR随便选就爆long long,因为他是把妹狂魔=V=)。
两种解法???第一种,求最大连续和,
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<utility>
#include<numeric>
#include<iterator>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cassert>
using std::cin;
using std::cout;
using std::endl;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
#define FOR(i,init,len) for(int i=(init);i<(len);++i)
#define For(i,init,len) for(int i=(init);i<=(len);++i)
#define fi first
#define se second
#define pb push_back
#define is insert
namespace IO {
inline char getchar() {
static const int BUFSIZE=;
static char buf[BUFSIZE],*begin,*end;
if(begin==end) {
begin=buf;
end=buf+fread(buf,,BUFSIZE,stdin);
if(begin==end) return -;
}
return *begin++;
}
}
inline void read(int &in) {
int c,symbol=;
while(isspace(c=IO::getchar()));
if(c=='-') { in=;symbol=-; }
else in=c-'';
while(isdigit(c=IO::getchar())) { in*=;in+=c-''; }
in*=symbol;
}
inline int read() { static int x;read(x);return x; }
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
#define PA(name,init,len) cout<<#name"["<<(len-init)<<"]=";FOR(_,init,len) cout<<name[_]<<" \n"[_==(len-1)];
#define Pa(name,init,len) cout<<#name"["<<(len-init+1)<<"]=";For(_,init,len) cout<<name[_]<<" \n"[_==(len)];
#define PV(name) cout<<#name"="<<name<<'\n'; const int maxn=1e6+;
int in[maxn];
ll d[][maxn][];
int n; int main() {
#ifdef MengLan
int Beginning=clock();
//freopen("in","r",stdin);
//freopen("out","w",stdout);
#endif // MengLan scanf("%d",&n);
For(i,,n) scanf("%d",in+i);
For(i,,) For(j,,n){
d[i][j][]=std::max({d[i-][j-][],d[i-][j-][],d[i][j-][]});
d[i][j][]=std::max(d[i][j-][],d[i][j-][])+in[j];
//printf("d[%d][%d][0]=%lld d[%d][%d][1]=%lld\n",i,j,d[i][j][0],i,j,d[i][j][1]);
}
ll ans=-1e18;
For(i,,n) ans=std::max(ans,d[][i][]);
printf("%lld\n",ans); #ifdef MengLan
printf("Time: %d\n",clock()-Beginning);
system("pause");
#endif // MengLan
return ;
}
Round #3的更多相关文章
- SQL Server 随机数,随机区间,随机抽取数据rand(),floor(),ceiling(),round(),newid()函数等
在查询分析器中执行:select rand(),可以看到结果会是类似于这样的随机小数:0.36361513486289558,像这样的小数在实际应用中用得不多,一般要取随机数都会取随机整数.那就看下面 ...
- SQL中Round(),Floor(),Ceiling()函数的浅析
项目中的一个功能模块上用到了标量值函数,函数中又有ceiling()函数的用法,自己找了一些资料,对SQL中这几个函数做一个简单的记录,方便自己学习.有不足之处欢迎拍砖补充 1.round()函数遵循 ...
- oracle的round函数和trunc函数
--Oracle trunc()函数的用法/**************日期********************/1.select trunc(sysdate) from dual --2013- ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- mathlab之floor,ceil,round,int以及fix函数
建议自己动手敲敲,网上很多人自己都没搞清楚然后好多错的.毕竟自己亲眼看到结果才有说服力. 以下是我亲眼见到的结果. 1.double floor(double)函数 floor()函数是常用的取整函数 ...
- SQL SERVER四舍五入你除了用ROUND还有其他方法吗?
引言 今天和测试沟通一个百分比计算方式时遇到一个问题, 我在存储过程里用到了强转CAST(32.678 AS DECIMAL(5,1)) 我认为该方式只会保留一位小数,我给测试的回复是我并没有用到四 ...
- JavaScript的几种Math函数,random(),ceil(),round(),floor()
1.Math.random():返回 0 ~ 1 之间的随机数.2.Math.ceil():返回值:返回大于或等于x,并且与之最接近的整数(如果x是正数,则把小数"入":如果x是负 ...
随机推荐
- [工具开发] 分享两个基于Heapster 和 Influxdb 的 Grafana 监控仪表盘模板
Info Collector: Heapster - /heapster- --metric-resolution=30s- --sink=influxdb:http://influxdb.defau ...
- JustSoso笔记
当时想了大半天,想着到底要怎么绕过MD5呢,结果还是没做出来,即使问了学长,自己还是漏了一个步骤,file=hint.php,特此笔记,又学到了个引用变量的知识 学习自 https://www.ctf ...
- 项目Alpha冲刺(团队)-第五天冲刺
格式描述 课程名称:软件工程1916|W(福州大学) 作业要求:项目Alpha冲刺(团队)-代码规范.冲刺任务与计划 团队名称:为了交项目干杯 作业目标:描述第五天冲刺的项目进展.问题困难.心得体会 ...
- 题解 P5301 【[GXOI/GZOI2019]宝牌一大堆】
这道题除了非常恶心以外也没有什么非常让人恶心的地方 当然一定要说有的话还是有的,就是这题和咱 ZJOI 的 mahjong 真的是好像的说~ 于是就想说这道题出题人应该被 锕 掉 noteskey 整 ...
- 【Ubuntu 18.04 搭建VNC服务器】
https://www.jianshu.com/p/f58fe5cdeb5f 桌面共享 Ubuntu 18.04自带桌面共享,可以将物理桌面共享给VNC.但是无法创建新的桌面. 具体参考 https: ...
- IntelliJ IDEA重启Tomcat
- 远程链接mysql
一. 设置账户密码 1. 创建用户:CREATE USER 'jiang'@'%' IDENTIFIED BY '1'; //%表示所有端口 2. 授予权限: GRANT ALL PRIVILEGES ...
- VMware vSphere 组件和功能
https://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.vsphere.introduction.doc_50%2FGUID- ...
- A页面跳转到B页面后打开指定tabs标签
A页面: <!DOCTYPE html><html lang="en" class="no-js"> <head> ...
- [原创]..\OBJ\gpio.axf: error: L6002U: Could not open file ..\obj\gpio.o: No such file
可以通过: 可以通过修改用户环境变量路径的方法解决:方法:右键我的电脑\属性\高级系统设置\环境变量\用户环境变量,找到变量TEMP和TMP,将变量值中的“%USERPROFILE%”使用“C:\us ...