UVa 10360 Rat Attack:枚举和优化

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1301

由于格子数远大于鼠窝,所以以鼠窝为出发点,增加鼠窝周围d范围内的“格子的值”,最后扫描每个格子输出最大格子值即可。

完整代码:

01./*0.125s*/
02.
03.#include<bits/stdc++.h>
04.using namespace std;
05.const int MAXN = 1030;
06.
07.int cnt[MAXN][MAXN];
08.
09.int main()
10.{
11.    int T, d, n, i, j, p, q;
12.    int x, y, num, lmax;
13.    int x_min, x_max, y_min, y_max;
14.    scanf("%d", &T);
15.    while (T--)
16.    {
17.        scanf("%d%d", &d, &n);
18.        memset(cnt, 0, sizeof(cnt));
19.        for (i = 0; i < n; ++i)
20.        {
21.            scanf("%d%d%d", &x, &y, &num);
22.            x_min = max(0, x - d), x_max = min(1024, x + d);
23.            y_min = max(0, y - d), y_max = min(1024, y + d);
24.            for (p = x_min; p <= x_max; ++p)
25.                for (q = y_min; q <= y_max; ++q)
26.                    cnt[p][q] += num;
27.        }
28.        lmax = x = y = 0;
29.        for (i = 0; i < 1025; ++i)
30.            for (j = 0; j < 1025; ++j)
31.                if (cnt[i][j] > lmax)
32.                    x = i, y = j, lmax = cnt[i][j];
33.        printf("%d %d %d\n", x, y, lmax);
34.    }
35.    return 0;
36.}

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索scanf
, int
格子
iso10360、10360日元、windows10360升级、10360、iso103602,以便于您获取更多的相关知识。

时间: 2024-09-30 21:08:56

UVa 10360 Rat Attack:枚举和优化的相关文章

UVa 10986:Sending email (Dijkstra优化, SPFA)

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1927 题目: Problem E Sending email Time Limit: 3 seconds "A new internet watchdog is creating a stir in Springfield. Mr. X, i

UVa 10167 Birthday Cake:枚举

10167 - Birthday Cake Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_problem&problem=1108 Background Lucy and Lily are twins. Today is their birthday. Mother buys a bir

UVa 140 Bandwidth:枚举全排列&amp;amp;剪枝搜索

140 - Bandwidth Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=76 Given a graph (V,E) where V is a set of nodes and E is a set of arcs in VxV, and anord

UVa 10125 Sumsets (折半枚举&amp;amp;二分查找)

10125 - Sumsets Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1066 Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S

UVa 471 Magic Numbers:枚举

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=412 直接枚举.代码中给出了一个用位运算判断数字中是否有重复数字的方法. 完整代码: 01./*0.032s*/ 02. 03.#include <cstdio> 04.const long long maxn = 9876543210LL; 05.

UVa 1225 Digit Counting:枚举

1225 - Digit Counting Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3666 N<10000,干脆O(NlogN)建表得了. 完整代码: /*0.012s*/ #include<cstdio> int c[10000]

uva 10730 - Antiarithmetic?

点击打开链接uva 10730 思路:枚举等差中项 分析: 1 给定一个n个数的序列判断是否有等差子序列 2 很明显我们如果要判断是否有等差子序列的话,只要去判断是否有长度为3的等差子序列 3 对于n<=10000,那么我们怎么去判断呢,由于我们要找的是是否有三个的等差序列,那么我们可以枚举每一个数作为等差中项,然后去判断 4 假设现在我们枚举num[i]作为等差中项,那么第一个数在0~i-1之间,第二个数是在i+1~n-1之间,这个时候如果单存利用for循环去找时间复杂度不能接受,那么我们想到

UVa 701 The Archeologists&#039; Dilemma: 数学及枚举

701 - The Archeologists' Dilemma Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=642 An archeologist seeking proof of the presence of extraterrestrials i

UVa 131 The Psychic Poker Player:枚举&amp;amp;模拟好题

131 - The Psychic Poker Player Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_problem&problem=67 In 5-card draw poker, a player is dealt a hand of five cards (which may