首页 > 代码库 > poj1319Pipe Fitters

poj1319Pipe Fitters

链接

算不上几何的水题

第一种为(int)a*(int)b;

第二种分宽高交换两种讨论。

每一个的高度除第一个为1外其它的都可以看着b/sqrt(3.0)/2;

 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9 #include<set>10 using namespace std;11 #define N 10000012 #define LL long long13 #define INF 0xfffffff14 const double eps = 1e-8;15 const double pi = acos(-1.0);16 const double inf = ~0u>>2;17 int dcmp(double x)18 {19     if(fabs(x)<eps) return 0;20     else return x<0?-1:1;21 }22 int solve(double a,double b,int ta,int tb)23 {24     if(dcmp(a-1)<0||dcmp(b-1)<0) return 0;25     int sum2;26     int k = (b-1)/(sqrt(3.0)/2)+1;27     if(dcmp(a-ta-0.5)>=0)28         sum2 = k*ta;29     else30         sum2 = (k+1)/2*ta+k/2*(ta-1);31     return sum2;32 }33 int main()34 {35     double a,b;36     while(scanf("%lf%lf",&a,&b)!=EOF)37     {38         int ta = int(a+eps);39         int tb = int(b+eps);40         int sum1 = ta*tb;41         int sum2 = solve(a,b,ta,tb);42         swap(a,b);43         sum2 = max(sum2,solve(a,b,tb,ta));44         if(sum1>=sum2)45         printf("%d grid\n",sum1);46         else47         printf("%d skew\n",sum2);48     }49     return 0;50 }
View Code