水灾(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.忘记了特判xx > n 或者 yy > m导致RE。。

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
inline void read(int &x)
{
x = ;char ch = getchar();char c = ch;
while(ch < '' || ch > '')c = ch, ch = getchar();
while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
if(c == '-')x = -x;
}
inline int max(int a, int b){return a > b ? a : b;}
inline int min(int a, int b){return a > b ? b : a;}
inline void swap(int &a, int &b){int tmp = a;a = b;b = tmp;} const int INF = 0x3f3f3f3f;
const int MAXN = + ;
const int MAXM = + ;
const int dirx[] = {,,,-};
const int diry[] = {,-,,}; char g[MAXN][MAXM];int n,m;
bool b[MAXN][MAXM];//人不能在拓展的地方
bool bb[MAXN][MAXM];//洪水不能再拓展的地方
int ex,ey;
struct Node
{
int x,y,t;//t代表第几轮
}q[];
int cnt; std::queue<int> q1,q2;//1为人的队列,2为洪水队列 inline int bfs()
{
int ans = ;
Node tmp;
while(!q1.empty())
{
int k;
//先做队列2
if(q2.empty())goto L1;
tmp = q[q2.front()];
k = tmp.t;
while(!q2.empty())
{
tmp = q[q2.front()];
if(k != tmp.t)break;
q2.pop();
for(int i = ;i < ;++ i)
{
int xx = tmp.x + dirx[i],yy = tmp.y + diry[i];
if(xx <= || yy <= || xx > n || yy > m)continue;
if(!bb[xx][yy])
{
q[++cnt] = Node{xx, yy, tmp.t + };
bb[xx][yy] = b[xx][yy] = true;
q2.push(cnt);
}
}
}
//再做队列1
L1: tmp = q[q1.front()];
k = tmp.t;
while(!q1.empty())
{
tmp = q[q1.front()];
if(k != tmp.t)break;
q1.pop();
for(int i = ;i < ;++ i)
{
int xx = tmp.x + dirx[i],yy = tmp.y + diry[i];
if(xx <= || yy <= || xx > n || yy > m)continue;
if(xx == ex && yy == ey)return k + ;
if(!b[xx][yy])
{
q[++cnt] = Node{xx, yy, tmp.t + };
b[xx][yy] = true;
q1.push(cnt);
}
}
}
}
return -;
} int main()
{
read(n);read(m);
for(register int i = ;i <= n;++ i)
{
scanf("%s", g[i] + );
for(register int j = ;j <= m;++ j)
{
if(g[i][j] == 'D')
ex = i, ey = j, bb[i][j] = true;
else if(g[i][j] == 'X')
bb[i][j] = b[i][j] = true;
else if(g[i][j] == '*')
{
b[i][j] = bb[i][j] = true;
q[++cnt] = Node{i,j,};
q2.push(cnt);
}
else if(g[i][j] == 'S')
{
b[i][j] = true;
q[++cnt] = Node{i,j,};
q1.push(cnt);
}
}
}
int ans = bfs();
if(ans == -)printf("ORZ hzwer!!!");
else printf("%d", ans);
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=)。

f[i][j]表示前i个数选j段且第i - 1个数必须选所能获得的最大收益
f[i][0] = max(f[i - 1][0] + num[i], num[i])
f[i][1] = max(f[i - 1][1] + num[i], f[j][0] + num[i]  j<i)
f[i][2] = max(f[i - 1][2] + num[i], f[j][1] + num[i]  j<i)

用最大值优化一下即可

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
inline void read(long long &x){x = ;char ch = getchar();char c = ch;while(ch < '' || ch > '')c = ch, ch = getchar();while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();if(c == '-')x = -x;}
inline long long max(long long a, long long b){return a > b ? a : b;}
inline long long min(long long a, long long b){return a > b ? b : a;}
inline void swap(long long &a, long long &b){int tmp = a;a = b;b = tmp;} const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long MAXN = + ; long long num[MAXN];
long long sum;
long long n;
long long ma; long long f[MAXN][]; long long ma1, ma2; long long ans; int main()
{
read(n);
ma1 = ma2 = ans = -INF;
for(register int i = ;i <= n;++ i)
read(num[i]);
f[][] = num[];
f[][] = max(num[] + num[], num[]);
f[][] = num[] + num[];
ma1 = max(f[][], f[][]);
ma2 = f[][];
f[][] = max(f[][] + num[], num[]);
f[][] = max(f[][] + num[], ma1 + num[]);
f[][] = num[] + num[] + num[];
ma2 = max(ma2, f[][]);
ma1 = max(ma1, f[][]);
for(register int i = ;i <= n;++ i)
{
f[i][] = max(f[i - ][] + num[i], num[i]);
f[i][] = max(f[i - ][] + num[i], ma1 + num[i]);
f[i][] = max(f[i - ][] + num[i], ma2 + num[i]);
ma1 = max(ma1, f[i][]);
ma2 = max(ma2, f[i][]);
}
ans = f[][];
for(register int i = ;i <= n;++ i)
{
ans = max(ans, f[i][]);
}
printf("%lld", ans);
return ;
}

密码锁 1000MS 512MB

Input: password.in

Output: password.out

【题目描述】

hzwer有一把密码锁,由N个开关组成。一开始的时候,所有开关都是关上的。当且仅当开关x1,x2,x3,...xk为开,其他开关为关时,密码锁才会打开。

他可以进行M种的操作,每种操作有一个size[i],表示,假如他选择了第i种的操作的话,他可以任意选择连续的size[i]个格子,把它们全部取反。(注意,由于黄金大神非常的神,所以操作次数可以无限>_<)

本来这是一个无关紧要的问题,但是,黄金大神不小心他的钱丢进去了,没有的钱他哪里能逃过被chenzeyu97 NTR的命运?>_<  于是,他为了虐爆czy,也为了去泡更多的妹子,决定打开这把锁。但是他那么神的人根本不屑这种”水题”。于是,他找到了你。

你的任务很简单,求出最少需要多少步才能打开密码锁,或者如果无解的话,请输出-1。

【输入格式】

第1行,三个正整数N,K,M,如题目所述。

第2行,K个正整数,表示开关x1,x2,x3..xk必须为开,保证x两两不同。

第三行,M个正整数,表示size[i],size[]可能有重复元素。

【输出格式】

输出答案,无解输出-1。

【样例输入1】

10 8 2

1 2 3 5 6 7 8 9

3 5

【样例输出1】

2

【样例输入2】

3 2 1

1 2

3

【样例输出2】

-1

【数据规模】

对于50%的数据,1≤N≤20,1≤k≤5,1≤m≤3;

对于另外20%的数据,1≤N≤10000,1≤k≤5,1≤m≤30;

对于100%的数据,1≤N≤10000,1≤k≤10,1≤m≤100。

先挂在这里,以后再说。。。

最新文章

  1. 用延迟加载解决CNZZ加载慢的问题
  2. JS操作cookies方法
  3. Ajax缓存解决办法(转载)
  4. java System.getProperty()参数大全
  5. [转]ASP.NET MVC3 + EF 性能优化解决方案以及最优架构
  6. python 学习中遇到的问题
  7. How to Call SharePoint 2013 API Service to Query The Lists
  8. 深入理解java虚拟机(2)------垃圾收集器和内存分配策略
  9. Program A-归并排序
  10. linux exec函数族
  11. C#序列化/反序列化
  12. Linux系统编程(3)——文件与IO之fcntl函数
  13. 纯CSS3实现自定义涂鸦风格的边框
  14. 什么?你竟然还没有用这几个chrome插件?
  15. Kafka知识总结
  16. obs源码uml
  17. 关于签名sign的坑
  18. java正则表达式 需要转义的字符
  19. 洛谷 P2679 子串 解题报告
  20. etree和Beautiful Soup的使用

热门文章

  1. JS 根据今天的日期获取本周星期一与星期天的日期
  2. [Ceoi2007]Royaltreasury
  3. mongoDB可视化工具RoBo 3T的安装和使用
  4. O(N)求出1~n逆元
  5. c++类成员函数的重载和覆盖有什么区别
  6. (转)AngularJS判断checkbox/复选框是否选中并实时显示
  7. python图像翻转
  8. python 日记 day3
  9. MyBatis配置文件(五)--objectFactory对象工厂
  10. Scrapy下载器中间件实现随机请求头和代理ip