您的位置:首页 > 其它

弱校联萌十一大决战之如日中天 G Gadget Hackwrench

2015-10-04 20:08 465 查看
Input/Output: standard input/output
Chip 'n' Dale have started a new business in the forest: they produce tiles of fixed rectangular size and pave roads with them.
Road paving rules are the following. Starting from one corner of the rectangular road tiles are paved side-by-side without gaps or overlaps. Tiles can be cut into pieces to be used to pave the road if and only if
the whole tile doesn't fit. Each tile contains a pattern with parallel lines that must be retained on the paved road. This makes their orientation significant: any tile or its piece can not be rotated. All tile connection lines are straight, parallel to one
of the road edges and either perpendicular or parallel to each other. Chip 'n' Dale always pave the road so that each edge of a tile is adjacent to not more than one other tile, and they always pave the road with the least possible amount of tile pieces on
the road.
Given the size of the road and the size of one tile please help Chip 'n' Dale determine the number of tiles they need to produce to fully pave the road.


Input

On the first line of input integers Widthroad and Lengthroad (1 ≤ Widthroad, Lengthroad ≤ 10 000)
are given — the width and the length of the road respectively.
On the second line of input integers Widthtile and Lengthtile (1 ≤ Widthtile ≤ Widthroad, 1 ≤ Lengthtile ≤ Lengthroad)
are given — the width and the length of the tile respectively.


Output

The first line of the output should contain a single integer number N — the minimal
number of whole tiles needed to fully pave the road according to Chip 'n' Dale road paving rules.


Sample Input

Input
10 10
2 2


Output
25


Input
3 5
2 2


Output
4


Input
35 17
25 1


Output
26




链接

可惜了我久违的!A啊啊啊啊 时间不够了 没写完T^T 题意当中有个点 学弟读题没读出来 就是只能长边对长边 短边对短边!而且不能转 实在不行了才能裁  

我读题还以为边角废料能凑在一起 后来学弟说要真能那么做 都裁成1x1的多好  哈哈 水题一个 就是一顿分类讨论 我丑陋的代码==

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int x,y,a,b;
int main()
{
// freopen("cin.txt","r",stdin);
while(~scanf("%d%d",&x,&y))
{
scanf("%d%d",&a,&b);
int sum=0;
sum+=((x/a)*(y/b));
// printf("%d\n",sum);
if((x%a==0)&&(y%b==0))
{
printf("%d\n",sum);
continue;
}
int ans1=x%a,ans2=y%b;
// printf("%d %d\n",ans1,ans2);
if(ans1==0)
{
if(ans2>(b)/2)
{
sum+=(x/a);
printf("%d\n",sum);
}
else
{
int tmp=b/ans2,tmp2=x/a;
sum+=tmp/tmp2;
if(tmp2%tmp) sum++;
printf("%d\n",sum);
}
continue;
}
if(ans2==0)
{
if(ans1>a/2)
{
sum+=y/b;
printf("%d\n",sum);
}
else
{
int tmp=a/ans1,tmp2=y/b;
sum+=tmp2/tmp;
if(tmp2%tmp) sum++;
printf("%d\n",sum);
}
continue;
}
if(ans1>(a)/2)
{
if(ans2>(b)/2)
{
sum+=x/a;
sum+=(y/b+1);
printf("%d\n",sum);
}
else
{
sum+=(y/b);
int tmp=b/ans2;
sum+=(x/(a*tmp));
if(x%(a*tmp))sum++;
printf("%d\n",sum);
}
}
else
{
if(ans2>(b)/2)
{
sum+=(x/a);
int tmp=a/ans1;
sum+=(y/(b*tmp)+1);
printf("%d\n",sum);
}
else
{
int tmp1,tmp2,sum1=0,sum2=0;
tmp1=y/b,tmp2=a/ans1;
sum1=tmp1/tmp2;
if(tmp1%tmp2) sum1++;
tmp1=b/ans2;
sum1+=(x/(tmp1*a));
if(x%(tmp1*a)) sum1++;
tmp1=x/a,tmp2=b/ans2;
sum2+=tmp1/tmp2;
if(tmp1%tmp2) sum2++;
tmp1=(a/ans1)*b;
sum2+=(y/tmp1);
if(y%tmp1) sum2++;
if(sum1<sum2) sum+=sum1;
else sum+=sum2;
//  printf("sum1=%d  sum2=%d\n",sum1,sum2);
printf("%d\n",sum);
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: