大致题意
已知不等式 ax + by + cz + d >0 。求参数 a, b, c, d 使,所有 Alliance systems 中的点都不满足不等式,且所有 Empire systems 中的点都满足不等式。
看完题目一脸懵逼…然后在 Discuss 见到了模拟退火法,学习了一下,Emmmm 真神奇,能 ac 是数据真的弱,整数内解决战斗。思路是不满足条件就简单地跳到下一个状态。
#include <cstdio>
#include <STDLIB.H>
#include <algorithm>
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define abs(x) ((x) < 0 ? -(x) : (x))
#define INF 0x3f3f3f3f
#define eps 1e-5
#define M_PI 3.14159265358979323846
#define MAX_E 10000
#define MAX_N 200
using namespace std;
struct point{
int x, y, z;
};
int N1, N2;
point A[MAX_N], E[MAX_N];
void solve(){
bool flag = false;
double a = 0, b = 0, c = 0, d = 0, cnt = 0;
while(!flag){
flag = true;
for(int i = 0; i < N1; i++){
double tmp = a * A[i].x + b * A[i].y + c * A[i].z + d;
if(tmp > 0){
flag = false;
a -= A[i].x, b -= A[i].y, c -= A[i].z, d -= 1;
}
}
for(int i = 0; i < N2; i++){
double tmp = a * E[i].x + b * E[i].y + c * E[i].z + d;
if(tmp <= 0){
flag = false;
a += E[i].x, b += E[i].y, c += E[i].z, d += 1;
}
}
}
printf("%f %f %f %f\n", a, b, c, d);
}
int main(){
while(~scanf("%d", &N1)){
for(int i = 0; i < N1; i++) scanf("%d%d%d", &A[i].x, &A[i].y, &A[i].z);
scanf("%d", &N2);
for(int i = 0; i < N2; i++) scanf("%d%d%d", &E[i].x, &E[i].y, &E[i].z);
if(N1 == -1 && N2 == -1) break;
solve();
}
return 0;
}