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 ...
随机推荐
- HTTP和HTTPS的请求和响应
HTTP协议(HyperText Transfer Protocol,超文本传输协议):是一种发布和接收 HTML页面的方法.HTTPS(Hypertext Transfer Protocol ove ...
- python 面向对象(进阶篇)转载武沛齐
上一篇<Python 面向对象(初级篇)>文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使 ...
- abap 开发之创建表维护生成器
在sap开发中有时需要对一些自建表维护数据,但又不想写程序,怎么办呢??这个时候我们可以直接生成个表维护生成器,为其定义一个事物码就ok了.以下是表格维护生成器的生成步骤. 首先我们需要先定义表.输入 ...
- Spark的Driver节点和Executor节点
转载自:http://blog.sina.com.cn/s/blog_15fc03d810102wto0.html 1.驱动器节点(Driver) Spark的驱动器是执行开发程序中的 main方法的 ...
- vue react angular对比
1.数据绑定 1)vue 把一个普通对象传给Vued的data选项,Vue会遍历此对象的所有属性,并使用Object.defineProperty将这些属性全部转为getter/setter.Obje ...
- Delphi APP 開發入門(一)重生的 Delphi
Delphi APP 開發入門(一)重生的 Delphi 分享: Share on facebookShare on twitterShare on google_plusone_share 閲讀 ...
- hdu1403 Longest Common Substring
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1403 题目: Longest Common Substring Time Limit: 800 ...
- struct2的xml文件中result的配置(转)
一个result代表了一个可能的输出.当Action类的方法执行完成时,它返回一个字符串类型的结果码,框架根据这个结果码选择对应的result,向用户输出.在com.opensymphony.xwor ...
- c++之旅:继承
继承 继承有关于权限的继承,多继承和虚继承 权限继承 权限继承有公有继承,保护继承和私有继承 公有继承 公有继承可以继承父类的public和protected属性和方法 #include <io ...
- Druid学习之路 (五)Druid的数据摄取任务类型
作者:Syn良子 出处:https://www.cnblogs.com/cssdongl/p/9885534.html 转载请注明出处 Druid的数据摄取任务类型 Druid支持很多种类型的数据摄取 ...