您的位置:首页 > 产品设计 > UI/UE

hdu 5301 Buildings 5308 I Wanna Become A 24-Point Master(构造)

2015-07-24 20:25 435 查看


Buildings

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 1331 Accepted Submission(s): 367



Problem Description

Your current task is to make a ground plan for a residential building located in HZXJHS. So you must determine a way to split the floor building with walls to make apartments in the shape of a rectangle. Each built wall must be paralled to the building's sides.

The floor is represented in the ground plan as a large rectangle with dimensions n×m,
where each apartment is a smaller rectangle with dimensions a×b located
inside. For each apartment, its dimensions can be different from each other. The number a and b must
be integers.

Additionally, the apartments must completely cover the floor without one 1×1 square
located on (x,y).
The apartments must not intersect, but they can touch.

For this example, this is a sample of n=2,m=3,x=2,y=2.



To prevent darkness indoors, the apartments must have windows. Therefore, each apartment must share its at least one side with the edge of the rectangle representing the floor so it is possible to place a window.

Your boss XXY wants to minimize the maximum areas of all apartments, now it's your turn to tell him the answer.



Input

There are at most 10000 testcases.

For each testcase, only four space-separated integers, n,m,x,y(1≤n,m≤108,n×m>1,1≤x≤n,1≤y≤m).



Output

For each testcase, print only one interger, representing the answer.



Sample Input

2 3 2 2
3 3 1 1




Sample Output

1
2

Hint
Case 1 :



You can split the floor into five 1×1 apartments. The answer is 1.

Case 2:



You can split the floor into three 2×1 apartments and two 1×1 apartments. The answer is 2.



If you want to split the floor into eight 1×1 apartments, it will be unacceptable because the apartment located on (2,2) can't have windows.




就是直接构造出答案。。。。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 10010
#define MAXM 100010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
using namespace std;

int Read()
{
    char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    int x = 0;
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}

void Print(int a)
{
     if(a>9)
         Print(a/10);
     putchar(a%10+'0');
}

int main()
{
    //fread;
    int n,m,x,y;
    while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF)
    {
        if(n>m)
        {
            swap(n,m);
            swap(x,y);
        }
        if(n==1)
        {
            puts("1");
            continue;
        }
        int ans=(n+1)/2;
        int a=min3(x-1,y,m-y+1);
        int b=min3(n-x,y,m-y+1);
        if(n&1&&n==m&&ans==x&&x==y)
            ans--;
        int res=max3(ans,a,b);
        printf("%d\n",res);
    }
    return 0;
}



I Wanna Become A 24-Point Master

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 757 Accepted Submission(s): 315

Special Judge


Problem Description

Recently Rikka falls in love with an old but interesting game -- 24 points. She wants to become a master of this game, so she asks Yuta to give her some problems to practice.

Quickly, Rikka solved almost all of the problems but the remained one is really difficult:

In this problem, you need to write a program which can get 24 points with n numbers,
which are all equal to n.



Input

There are no more then 100 testcases and there are no more then 5 testcases with n≥100.
Each testcase contains only one integer n (1≤n≤105)



Output

For each testcase:

If there is not any way to get 24 points, print a single line with -1.

Otherwise, let A be
an array with 2n−1 numbers
and at firsrt Ai=n (1≤i≤n).
You need to print n−1 lines
and the ith
line contains one integer a,
one char b and
then one integer c, where 1≤a,c<n+i and b is
"+","-","*" or "/". This line means that you let Aa and Ac do
the operation b and
store the answer into An+i.

If your answer satisfies the following rule, we think your answer is right:

1. A2n−1=24

2. Each position of the array A is
used at most one tine.

3. The absolute value of the numerator and denominator of each element in array A is
no more than 109



Sample Input

4




Sample Output

1 * 2
5 + 3
6 + 4




n个值为n的数通过四则运算得到24 通过构造得到答案

当有12个数时 (n+n+n+n)/n*(n+n+n+n+n+n)/n 4*6=24 其他的可以通过得到一个0 不断乘以n 最后24+0

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 10010
#define MAXM 100010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)

using namespace std;

int Read()
{
    char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    int x = 0;
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}

void Print(int a)
{
     if(a>9)
         Print(a/10);
     putchar(a%10+'0');
}

int main()
{
    //fread;
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n<=3)
        {
            puts("-1");
            continue;
        }
        if(n==4)
        {
            puts("1 * 2");
            puts("5 + 3");
            puts("6 + 4");
            continue;
        }
        if(n==5)
        {
            puts("1 * 2");
            puts("6 * 3");
            puts("7 - 4");
            puts("8 / 5");
            continue;
        }
        if(n==6)
        {
            puts("1 + 2");
            puts("3 + 4");
            puts("5 - 6");
            puts("7 + 8");
            puts("9 + 10");
            continue;
        }
        if(n==7)
        {
            puts("1 + 2");
            puts("8 + 3");
            puts("9 / 4");
            puts("5 / 6");
            puts("7 + 11");
            puts("12 * 10");
            continue;
        }
        if(n==8)
        {
            puts("1 + 2");
            puts("9 + 3");
            puts("5 - 4");
            puts("6 * 11");
            puts("7 * 12");
            puts("8 * 13");
            puts("10 + 14");
            continue;
        }
        if(n==9)
        {
            puts("1 / 2");  //10  1
            puts("3 - 10"); //11  8
            puts("4 + 5");  //12 18
            puts("12 + 6"); //13 27
            puts("13 / 7"); //14  3
            puts("11 * 14");//15 24
            puts("8 - 9");  //16  0
            puts("15 + 16");
            continue;
        }
        if(n==10)
        {
            puts("1 + 2");  //11 20
            puts("3 + 4");  //12 20
            puts("5 + 6");  //13 20
            puts("7 - 8");  //14 0
            puts("9 * 14"); //15 0
            puts("12 + 13");//16 40
            puts("16 / 10");//17 4
            puts("17 + 11");//18 24
            puts("18 + 15");
            continue;
        }
        if(n==11)
        {
            puts("1 + 2");  //12 22
            puts("3 + 4");  //13 22
            puts("13 / 5"); //14 2
            puts("14 + 12");//15 24
            puts("6 - 7");  //16 0
            puts("8 * 16"); //17 0
            puts("9 * 17"); //18 0
            puts("10 * 18");//19 0
            puts("11 * 19");//20 0
            puts("20 + 15");//21 24
            continue;
        }
        if(n==12)
        {
            puts("1 + 2"); //13 2n
            printf("%d + 3\n",n+1); //14 3n
            printf("%d + 4\n",n+2); //15 4n
            printf("%d + 5\n",n+3); //16 5n
            printf("%d + 6\n",n+4); //17 6n
            printf("%d / 7\n",n+5); //18(n+6) 6
            puts("8 + 9"); //19 2n
            printf("%d + 10\n",n+7); //20 3n
            printf("%d + 11\n",n+8); //21 4n
            printf("%d / 12\n",n+9); //22(n+10) 4
            printf("%d * %d\n",n+6,n+10); //23(n+11) 24
            continue;
        }
        if(n==13)
        {
            puts("1 / 2");  //14 1
            puts("3 - 14"); //15 12
            puts("4 + 5");  //16 26
            puts("16 / 6"); //17 2
            puts("15 * 17");//18 24
            puts("7 - 8");  //19 0
            puts("9 * 19"); //20 0
            puts("10 * 20"); //21 0
            puts("11 * 21"); //22 0
            puts("12 * 22"); //23 0
            puts("13 * 23"); //24 0
            puts("24 + 18"); //25 24
            continue;
        }
        puts("1 + 2"); //13 2n
        printf("%d + 3\n",n+1); //14 3n
        printf("%d + 4\n",n+2); //15 4n
        printf("%d + 5\n",n+3); //16 5n
        printf("%d + 6\n",n+4); //17 6n
        printf("%d / 7\n",n+5); //18(n+6) 6
        puts("8 + 9"); //19 2n
        printf("%d + 10\n",n+7); //20 3n
        printf("%d + 11\n",n+8); //21 4n
        printf("%d / 12\n",n+9); //22(n+10) 4
        printf("%d * %d\n",n+6,n+10); //23(n+11) 24
        puts("13 - 14");//n+12 0
        int tep=n+12;
        for(int i=15;i<=n;i++)
        {
            printf("%d * %d\n",i,tep);
            tep++;
        }
        printf("%d + %d\n",n+11,tep); //24=0
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: