1 /*UVA 11722 2 简单二维线性规划问题: 3 输入:5 integers t1, t2, s1, s2, w (360 ≤ t1 < t2 < 1080, 360 ≤ s1 < s2 < 1080 and 1 ≤ w ≤ 90). 4 目标函数:0<=|s-t|<=w;计算目标的补集更简单 5 步骤:画出坐标轴,注意分类讨论; 6 分类讨论:(图形见书P141) 7 确定4个交点: 8 A(t1,t1+w),B(s2-w,s2),C(t2,t2-w),D(s1+w,s1) 9 aim1=0.5*(s2-ay)*(bx-t1),ay>=s1 && bx<=t2;10 aim1=0.5*((s2-ay)+(s2-(t2+w))*(t2-t1), ay>=s1 && bx>t2;11 aim1=0.5*(s1-w-t1+(bx-t1))*(s2-s1),ay=t1;14 aim2=0.5*((t1-w-s1)+(cy-s1))*(t2-t1), cy<=s2 && dx s2 && dx<=t1;16 aim2=0;//否则17 aim=((s2-s1)*(t2-t1)-aim1-aim2)/(s2-s1)*(t2-t1);18 */19 20 #include 21 #include 22 #include 23 #include 24 #include 25 #include 26 #include 27 #include 28 #include