zoukankan      html  css  js  c++  java
  • ZOJ 2705 Dividing a Chocolate

     

    Dividing a Chocolate

    Time Limit: 2000ms
    Memory Limit: 65536KB
    This problem will be judged on ZJU. Original ID: 2705
    64-bit integer IO format: %lld      Java class name: Main
    Type:  None Graph Theory     2-SAT     Articulation/Bridge/Biconnected Component     Cycles/Topological Sorting/Strongly Connected Component     Shortest Path         Bellman Ford         Dijkstra/Floyd Warshall     Euler Trail/Circuit     Heavy-Light Decomposition     Minimum Spanning Tree     Stable Marriage Problem     Trees     Directed Minimum Spanning Tree     Flow/Matching         Graph Matching             Bipartite Matching             Hopcroft–Karp Bipartite Matching             Weighted Bipartite Matching/Hungarian Algorithm         Flow             Max Flow/Min Cut             Min Cost Max Flow DFS-like     Backtracking with Pruning/Branch and Bound     Basic Recursion     IDA* Search     Parsing/Grammar     Breadth First Search/Depth First Search     Advanced Search Techniques         Binary Search/Bisection         Ternary Search Geometry     Basic Geometry     Computational Geometry     Convex Hull     Pick's Theorem Game Theory     Green Hackenbush/Colon Principle/Fusion Principle     Nim     Sprague-Grundy Number Matrix     Gaussian Elimination     Matrix Exponentiation Data Structures     Basic Data Structures     Binary Indexed Tree     Binary Search Tree     Hashing     Orthogonal Range Search     Range Minimum Query/Lowest Common Ancestor     Segment Tree/Interval Tree     Trie Tree     Sorting     Disjoint Set String     Aho Corasick     Knuth-Morris-Pratt     Suffix Array/Suffix Tree Math     Basic Math     Big Integer Arithmetic     Number Theory         Chinese Remainder Theorem         Extended Euclid         Inclusion/Exclusion         Modular Arithmetic     Combinatorics         Group Theory/Burnside's lemma         Counting     Probability/Expected Value Others     Tricky     Hardest     Unusual     Brute Force     Implementation     Constructive Algorithms     Two Pointer     Bitmask     Beginner     Discrete Logarithm/Shank's Baby-step Giant-step Algorithm     Greedy     Divide and Conquer Dynamic Programming                  

    The boy and Karlsson are dividing a chocolate that the boy's parents have presented him for his birthday. A chocolate is a rectangle that consists of m × n chocolate squares, separated from each other by cutlines.

    Of course, Karlsson does the dividing. First Karlsson divides the chocolate into two rectangular pieces, breaking it along some cutline. Since Karlsson wants to divide chocolate fairly, he would not be satisfied if the two pieces have different sizes. In this case he cuts away the piece equal to the smaller piece out of the larger piece, and eats it. If the pieces are still not equal, he does so again, and so on. After the pieces are finally equal, Karlsson eats one of the pieces, and the boy eats another.

    Karlsson wants to make an initial cut in such a way that he would eat as much chocolate as possible. However, the boy knows that Karlsson likes chocolate very much, and he watches for the process closely. Karlsson must be very careful not to offend the boy. So he must not successively cut away and eat chocolate from the same piece --- this would seem too suspicious to the boy.

    Help Karlsson to find out how much chocolate he can eat.

    Input

    There are mutiple cases in the input file.

    Each case contains m and n (1 <= m, n <= 109 ).

    There is an empty line after each case.

    Output

    Output one integer number --- how many chocolate squares Karlsson can eat. If Karlsson cannot divide chocolate using his method, output 0 instead.

    There should be am empty line after each case.

    Sample Input

    6 5

    Sample Output

    24

    In the example Karlsson must initially break a chocolate into pieces of sizes 3 × 6 and 2 × 6 . After that he can eat all chocolate but the boy's piece that would finally be 1 × 6 . Karlsson cannot, for example, cut a chocolate initially into pieces of sizes 5 × 5 and 1 × 5 --- after doing so, he would have to successively cut a piece away from the first one several times, that would offend the boy.

    Source

    Tags 




    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    long long int fib[]={0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,
    17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,
    14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170,
    1836311903};
    long long int n,m;

    const int INF=0x3f3f3f3f;

    int main()
    {
        while(cin>>n>>m)
        {
            long long int kn=INF,km=INF;
            for(int i=3;fib<=n;i++)
            {
                if(n%fib==0)
                {
                    kn=min(kn,n/fib);
                }
            }
            for(int i=3;fib<=m;i++)
            {
                if(m%fib==0)
                {
                    km=min(km,m/fib);
                }
            }
            if(kn==INF&&km==INF)
            {
                puts("0");
                putchar(10);
            }
            else
            {
                long long int ans=min(kn*m,km*n);
                printf("%lld ",m*n-ans);
            }
        }
        return 0;
    }
    * This source code was highlighted by YcdoiT. ( style: Vs )





  • 相关阅读:
    hdu 1042 N!
    hdu 1002 A + B Problem II
    c++大数模板
    hdu 1004 Let the Balloon Rise
    hdu 4027 Can you answer these queries?
    poj 2823 Sliding Window
    hdu 3074 Multiply game
    hdu 1394 Minimum Inversion Number
    hdu 5199 Gunner
    九度oj 1521 二叉树的镜像
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350898.html
Copyright © 2011-2022 走看看