ZOJ 3706 Break Standard Weight (simulation)
Question:
Here are two objects of the standard weight (the mass is an integer). You can divide one of them into two (integers) and calculate the maximum weight of the three objects.
In fact, there are 13 cases in total, and the data volume is small. Use set to exclude duplicates. Pay attention to 0.
Code:
#include
#include
#include
#include
#include using namespace std;int cal(int a,int b,int c){set
cnt;cnt.insert(abs(a));cnt.insert(abs(b));cnt.insert(abs(c));cnt.insert(abs(a+b));cnt.insert(abs(a+c));cnt.insert(abs(b+c));cnt.insert(abs(a-b));cnt.insert(abs(a-c));cnt.insert(abs(b-c));cnt.insert(abs(a+b+c));cnt.insert(abs(a+b-c));cnt.insert(abs(a+c-b));cnt.insert(abs(b+c-a));cnt.erase(0);return cnt.size();}int main(){int t,a,b,maxx;scanf(%d,&t);while(t--){maxx=0;scanf(%d%d,&a,&b);for(int i=1;i<=a/2;i++){maxx=max(cal(i,a-i,b),maxx);}for(int i=1;i<=b/2;i++){maxx=max(cal(i,b-i,a),maxx);}printf(%d,maxx);}return 0;}