我正在练习ACM ICPC past problems http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1030
我无法解决这个问题,也完全不知道如何在3秒的时间内有效地解决这个问题。我认为这个问题是基于数论的,但不知道具体该怎么做。谢谢!
发布于 2018-07-25 17:21:34
虽然转化为向量问题,但三维向量和如此多的变量有点棘手,因此我们可以首先降维,并将原始方程更改为:A[1]* (s[1][2]-s[1][1], s[1][3]-s[1][1]) + a[2]* (s[2][2]- s[2][1], s[2][3]- s[2][1]) +.....+a[n]* (s[n][2]- s[n][1],..+a[n]*) = (())。将二维矢量视为平面坐标系中从原点开始的矢量。如果只有两个矢量,因为a[i]是一个非负数,所以当只有两个矢量时,角度必须是PI。如果两个相邻向量之间的夹角不大于PI,则N个向量可满足上述方程。代码不长,但它需要一个数学思维T_T这里是正确的代码。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=1000+5;
const double PI=acos(-1);
int main()
{
int n;
double A[maxn];
while(scanf("%d",&n),n)
{
int s1,s2,s3;
for(int i=0;i<n;i++)
{
scanf("%d%d%d",&s1,&s2,&s3);
A[i]=atan2(s2-s1,s3-s1);
}
sort(A,A+n);
double tmp=0;
for(int i=1;i<n;i++)
tmp=max(tmp,A[i]-A[i-1]);
tmp=max(tmp,A[0]-A[n-1]+2*PI);
if(tmp<=PI)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}发布于 2012-04-08 02:49:02
所以我相信:
(a1,b1,c1), (a2,b2,c2) ... (an,bn,cn)如果存在非负系数,则需要决定:
X = (x1,x2,...,xn)这样的话
x1*a1 + x2*a2 + ... + xn*an ==
x1*b1 + x2*b2 + ... + xn*bn ==
x1*c1 + x2*c2 + ... + xn*cn只需要一点线性代数就可以了。
提示:尝试构造一个n ==为4的输入,这样所有4个xis都必须是正的才能解决问题(而不是只有3个就能解决)。这个是可能的吗?
https://stackoverflow.com/questions/10057168
复制相似问题