uva1393 Highways

留坑(p.339)

http://blog.csdn.net/accelerator_/article/details/26132853

为啥不-(gcd(i-1, j-1) == 1)?

rjl的算法:枚举有效包围盒的数量

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<algorithm>
 5 #include<iostream>
 6
 7 using namespace std;
 8
 9 void setIO(const string& s) {
10     freopen((s + ".in").c_str(), "r", stdin);
11     freopen((s + ".out").c_str(), "w", stdout);
12 }
13 template<typename Q> Q read(Q& x) {
14     static char c, f;
15     for(f = 0; c = getchar(), !isdigit(c); ) if(c == ‘-‘) f = 1;
16     for(x = 0; isdigit(c); c = getchar()) x = x * 10 + c - ‘0‘;
17     if(f) x = -x;
18     return x;
19 }
20 template<typename Q> Q read() {
21     static Q x; read(x); return x;
22 }
23
24 const int N = 300 + 10;
25
26 int g[N][N];
27
28 int main() {
29 #ifdef DEBUG
30     freopen("in.txt", "r", stdin);
31     freopen("out.txt", "w", stdout);
32 #endif
33
34     for(int i = 1; i <= 300; i++) {
35         for(int j = i; j <= 300; j++) {
36             g[i][j] = g[j][i] = __gcd(i, j);
37         }
38     }
39
40     int n, m;
41     while(scanf("%d%d", &n, &m), n) {
42         int ans = 0;
43         for(int a = 1; a <= m; a++) {
44             for(int b = 1; b <= n; b++) {
45                 if(g[a][b] == 1) {
46                     int c = max(0, m - (a << 1)) * max(0, n - (b << 1));
47                     ans += (m - a) * (n - b) - c;
48                 }
49             }
50         }
51         printf("%d\n", ans << 1);
52     }
53
54     return 0;
55 }

时间: 2024-08-24 09:05:39

uva1393 Highways的相关文章

[spoj104][Highways] (生成树计数+矩阵树定理+高斯消元)

In some countries building highways takes a lot of time... Maybe that's because there are many possiblities to construct a network of highways and engineers can't make up their minds which one to choose. Suppose we have a list of cities that can be c

UVA - 1393 Highways

Description Hackerland is a happy democratic country with m×n cities, arranged in a rectangular m by n grid and connected by m roads in the east-west direction and n roads in the north-south direction. By public demand, this orthogonal road system is

poj 2485 Highways

链接:poj 2485 题意:输入n个城镇相互之间的距离,输出将n个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,只不过要求的不是最小价值,而是最小生成树中的最大权值,只需要加个判断 比较最小生成树每条边的大小就行 #include<cstdio> #include<algorithm> using namespace std; int f[510],n,m; struct stu { int a,b,c; }t[20100]; int cmp(struct

POJ 2485 Highways 最小生成树 (Kruskal)

Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that i

POJ 2485 Highways (求最小生成树中最大的边)

Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that i

[2016-01-27][POJ][1751][B - Highways]

[2016-01-27][POJ][1751][B - Highways] B - Highways Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1751 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a

POJ 2485 Highways(最小生成树+ 输出该最小生成树里的最长的边权)

Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23426   Accepted: 10829 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Fl

POJ2485 Highways【Prim】

Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23247 Accepted: 10720 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatop

POJ2485:Highways(模板题)

http://poj.org/problem?id=2485 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning t