ZOJ Problem Set

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <iostream>
#include <algorithm>
using namespace std;


set<int> ST;


int find(int a, int b, int c)
{
    ST.clear();

    ST.insert(0);

    ST.insert(a);
    ST.insert(b);
    ST.insert(c);


    ST.insert(a+b);
    ST.insert(a+c);
    ST.insert(b+c);

    ST.insert(abs(a-b));
    ST.insert(abs(b-c));
    ST.insert(abs(a-c));

    ST.insert(abs(a+b-c));
    ST.insert(abs(a+c-b));
    ST.insert(abs(b+c-a));


    ST.insert(a+b+c);

    return ST.size() - 1;
}


int main(void)
{
    int T;
    scanf("%d", &T);

    while(T--)
    {
        int x, y;
        scanf("%d%d", &x, &y);

        int max = -1;

        for(int i = 1; i <= (x/2); ++i)
        {
            int t = find(i, x-i, y);
            if(t > max) max = t;
        }

        for(int i = 1; i <= (y/2); ++i)
        {
            int t = find(x, i, y-i);
            if(t > max) max = t;
        }
        printf("%d
", max);
    }
}
原文地址:https://www.cnblogs.com/Alandre/p/3612322.html