首页 技术 正文
技术 2022年11月16日
0 收藏 983 点赞 2,488 浏览 6074 个字

题源:感谢 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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297