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

uva1393 Highways

时间:2016-01-06 17:49:06      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

留坑(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 }
View Code

 

uva1393 Highways

标签:

原文地址:http://www.cnblogs.com/showson/p/5106050.html

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