USACO 3.4 Electric Fence(pick定理)
模板题。精度让我错了一次。
1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: fence9 5 */ 6 #include <cstdio> 7 #include <cstring> 8 #include <iostream> 9 #include <cmath> 10 using namespace std; 11 int gcd(int a,int b) 12 { 13 return b == 0?a:gcd(b,a%b); 14 } 15 int main() 16 { 17 int x,y,p; 18 int a,s,b; 19 freopen("fence9.in","r",stdin); 20 freopen("fence9.out","w",stdout); 21 scanf("%d%d%d",&x,&y,&p); 22 s = p*y; 23 b = gcd(x,y)+p; 24 b += gcd(fabs(p-x),y); 25 a = (s+2-b)/2; 26 printf("%d\n",a); 27 return 0; 28 }