摘要:
Pick公式:平面上以格子点为顶点的简单多边形,如果边上的点数为on,内部的点数为in,则它的面积为area=on/2+in-1利用gcd求每个边上的点数。View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;struct Point{ int x, y;}point[3];void input(){ for (int i = 0; i < 3; i++) scanf("%d%d&q 阅读全文
posted @ 2011-10-08 14:33
undefined2024
阅读(299)
评论(0)
推荐(0)
摘要:
简单题View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define maxn 100005int n, f[maxn];void input(){ for (int i = 0; i < n; i++) scanf("%d", &f[i]);}void work(){ int i = 0, j = 0; long long ans = 0; while (1 阅读全文
posted @ 2011-10-08 14:12
undefined2024
阅读(340)
评论(0)
推荐(0)
摘要:
题意:给出n个5维坐标点,求最远两点的曼哈顿距离。分析:对于两维的情况,两个点(x1,y1)(x2,y2)之间的距离为|x1-x2|+|y1-y2|,可能取±(x1-x2)±(y1-y2),假如真实的情况是(x1-x2)+(y1-y2),那个在其他情况下算出来的关于这两个点的最大距离肯定比这个小(去掉绝对值符号了),这个式子除了对应同一维的两个值(如:x1和x2)是相减关系外(但不一定谁减谁)其余符号都是不确定的。我们可以把这个相减关系提取出来,变为(±x1±y1)-(±x2±y2)。(注意:这里x1和x2前面的符号是一致的,y1和y 阅读全文
posted @ 2011-10-08 13:37
undefined2024
阅读(531)
评论(0)
推荐(0)
摘要:
题意:给出n,求1/n=1/x+1/y(n,x,y=1,2,3...)的解的个数分析:n = (x*y)/(x+y) (x+y)*n = x*y设x = n+a; y = n+b带入可以得到n*n = a*b题目就转化成了求所有整数对使得a*b = n*n。即求n*n的约数个数,由于约数都是成对出现的,两数乘积为n^2,为奇数是因为n与n成对出现,而只计算了1次。为避免重复,设约数个数为p,(p + 1)/2即为所求。然而n*n过大不能直接求约数。我们用求质因子的方法求约数个数,我们只需求n的素因子,每个个数乘2即为n*n的每个素因子个数。View Code #include <iost 阅读全文
posted @ 2011-10-08 12:46
undefined2024
阅读(220)
评论(0)
推荐(0)