codeforce 35C fire again
2017-08-25 17:04:07
writer:pprp
题目描述:
• Codeforces 35C Fire Again
• N*M的格子,最开始有K个点 (坐标给定) 开始着火
• 每一秒着火的点会扩散到与其距离为1的其他点
• 求最后一个着火的点
• 1 ≤ n, m ≤ 2000
• 1 ≤ K ≤ 10
模拟的题,本来想用dfs做感觉有点复杂,
可以通过判断两个点之间横纵距离之和来计算出时间
参见的是cf上某位大佬的代码,差距还是很大,要加油了,
话说cf真是好,越来越觉得cf好用了
代码如下:
/*
theme:cf 35c fire again
writer:pprp
declare:reference from WannabeStronger
type: 模拟
date:2017/8/25
*/ #include <cstdio>
#include <bits/stdc++.h> using namespace std; struct point
{
int x, y;
} pt[]; const int maxn = ; int mp[maxn][maxn]; int main()
{
freopen("input.txt","r",stdin);//这几句很神奇,不知道为什么加上这个就可以运行过去,不加就过不去
freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false); int n, m, k;
cin >> n >> m >>k; for(int i = ; i <= k ; i++)
cin >> pt[i].x >> pt[i].y;
//初始化
for(int i = ; i <= n ; i++)
{
for(int j = ; j <= m ; j++)
{
mp[i][j] = 1e6;
}
}
//开始枚举着火点的时间
for(int l = ; l <= k ; l++)
{
for(int i = ; i <= n ; i++)
{
for(int j = ; j <= m ; j++)
{
int _x = abs(i - pt[l].x);
int _y = abs(j - pt[l].y);
mp[i][j] = min(_x+_y, mp[i][j]);
}
}
}
//找到最大值,也就是最晚被烧到的树
int ans = INT_MIN;
int ans_x, ans_y;
for(int i = ; i <= n ; i++)
{
for(int j = ; j <= m ; j++)
{
if(ans < mp[i][j])
{
ans = mp[i][j];
ans_x = i;
ans_y = j;
}
}
} cout << ans_x << " " << ans_y << endl; return ;
}
关于freopen部分的代码找到原因了

题目中有要求所以要这样做
codeforce 35C fire again的更多相关文章
- Codeforce E. Fire
E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- codeforce E. Fire背包
E. Fire time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Fire Again CodeForces - 35C (BFS)
After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows ...
- 关于SequeezeNet中的Fire Module
在论文<SQUEEZENET: ALEXNET-LEVEL ACCURACY WITH 50X FEWER PARAMETERS AND <0.5MB MODEL SIZE>中,作者 ...
- FZU 2150 Fire Game
Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- Fire
Fire 分析: 首先,明确题意:b1,b2,--,bn 交换为b2,--,bn,b1,但这并不是意味着只能从b1开始交换,(这点从样例中可以看出),并且也不意味着交换的必须是连续的一串,可以是几个单 ...
- Android 轻量级输入校验库:Fire Eye
Fire Eye是一款轻量级简单易用的Android校验库. FireEye 2.0 在 1.0 的基础上,全部重写了代码,并优化了架构,性能上和逻辑上都大大提升.只需要几行代码,即可验证用户输入,并 ...
- ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪
FZU 2150 Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
随机推荐
- python中的itertools
在量化数据处理中,经常使用itertools来完成数据的各种排列组合以寻找最优参数 import itertools #1. permutations: 考虑顺序组合元素 items = [1, 2, ...
- python中yield使用
16.yield使用 列表推导与生成器表达式 当我们创建了一个列表的时候,就创建了一个可以迭代的对象: >>> squares=[n*n for n in range(3)] ...
- 持续集成之戏说Check-in Dance(转)
add by zhj: 先说一下持续集成的定义,这是ThoughtWorks首席科学家Martin Fowler在<持续集成>第二版中给出的,“持续集成是一种软件开发实践.在持续集成中,团 ...
- 17.Delete Methods-官方文档摘录
介绍delete的方法 MongoDB provides the following methods to delete documents of a collection: db.collectio ...
- 我不想用for循环
为什么要挑战自己在代码里不写for loop?因为这样可以迫使你去使用比较高级.地道的语法或库.文中以python为例子,讲了不少大家其实在别人的代码里都见过.但自己很少用的语法. 这是一个挑战.我要 ...
- struts2之Action获取请求参数与web元素
文章思路清晰 http://blog.csdn.net/zeqblog/article/details/8665052
- 出现 Request Entity Too Large问题的解决方法
根据经验判断应该是上传文件大小被限制了,检查了应用配置是10M,把它设置成100M,重启服务也不能解决问题. 原来我们的tomcat是通过nginx发现服务代理的,问题就出现nginx服务器上,原来n ...
- 模块讲解----json与pickle模块的区别
1.在生产中,dumps和loads只进行一次,而且要用w把原来的数据冲掉,从而保证每次都是最新的. 2.虚拟机的快照,是每个快照都有一个文件,而不是全都不放在一起. 3.如果想生产好几个序列化,就生 ...
- 细说PHP的FPM
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++基础概念++ C ...
- Android Study Notes
@1:按下back键退回到home界面时,会调用onDestroy() 按下back键时会调用onDestroy()销毁当前的activity,重新启动此activity时会调用onCreate()重 ...