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[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部分的代码找到原因了

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

时间: 2024-10-05 11:38:09

codeforce 35C fire again的相关文章

Fire Again CodeForces - 35C (BFS)

After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row would

FZU 2150 Fire Game(点火游戏)

p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h2 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: left; font-family: 宋体; font-weight: bold; font-size: 18.0000pt } h3 {

ZOJ 3820 Building Fire Stations

Building Fire Stations Time Limit: 5000ms Memory Limit: 131072KB This problem will be judged on ZJU. Original ID: 382064-bit integer IO format: %lld      Java class name: Main Special Judge Marjar University is a beautiful and peaceful place. There a

HDU 1045 - Fire Net (最大独立集)

题意:给你一个正方形棋盘.每个棋子可以直线攻击,除非隔着石头.现在要求所有棋子都不互相攻击,问最多可以放多少个棋子. 这个题可以用搜索来做.每个棋子考虑放与不放两种情况,然后再判断是否能互相攻击来剪枝.最后取可以放置的最大值. 这里我转化成求最大独立集来做. 首先将每个空地编号,对于每个空地,与该位置可以攻击到的空地连边.找最多的空地使得不互相攻击,即求该图的最大独立集.与搜索做法基本一致,但是说法略有不同. 1 #include<iostream> 2 #include<cstring

Fire! 又是图 bfs

Joe works in a maze.  Unfortunately, portions of the maze havecaught on  re, and the owner of the maze neglected to create a  reescape plan. Help Joe escape the maze.Given Joe's location in the maze and which squares of the mazeare on  re, you must d

ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪

FZU 2150 Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this boar

Fire Maze(广度优先搜索)

Fire Maze Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 53(19 users) Total Accepted: 26(17 users) Rating: Special Judge: No Description After escaping from Figo's chase, Severus falls into a N * M maze designed by Figo. At first, Severus is

(简单) UVA 11624 Fire! ,BFS。

Description Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe's location in the maze and which squares of the maze are o

(简单) FZU 2150 Fire Game ,Floyd。

Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start to fire all the grass. Firstl