码迷,mamicode.com
首页 > 其他好文 > 详细

codeforce 35C fire again

时间:2017-08-25 17:44:41      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:ann   cin   运行   str   ima   cout   enc   for   code   

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[11];

const int maxn = 2500;

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 = 1; i <= k ; i++)
        cin >> pt[i].x >> pt[i].y;
    //初始化
    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 1 ; j <= m ; j++)
        {
            mp[i][j] = 1e6;
        }
    }
    //开始枚举着火点的时间
    for(int l = 1 ; l <= k ; l++)
    {
        for(int i = 1 ; i <= n ; i++)
        {
            for(int j = 1 ; 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 = 1 ; i <= n ; i++)
    {
        for(int j = 1; 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 0;
}

 关于freopen部分的代码找到原因了

技术分享

题目中有要求所以要这样做

codeforce 35C fire again

标签:ann   cin   运行   str   ima   cout   enc   for   code   

原文地址:http://www.cnblogs.com/pprp/p/7428910.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!