D题卡了一万年,求看看这个a[0]求值语句放的位置问题
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long int ll;
const int maxn = 500 + 50;
//const int p = 1e9 + 7;
struct node
{
int x;
int y;
};
node s[maxn];
int length(node & A, node & B)
{
return (A.x - B.x)*(A.x - B.x) + (A.y - B.y)*(A.y - B.y);//两点线段长的平方
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d%d", &s[i].x, &s[i].y);
}
int cnt = 0;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
{
if ((s[j].y - s[i].y)*(s[k].x - s[j].x) == (s[k].y - s[j].y)*(s[j].x - s[i].x))
continue;
//a[0]=length(s[i],s[j]);//a[0]求值放到这里就AC
a[1] = length(s[i], s[k]);
a[2] = length(s[j], s[k]);
sort(a, a + 3);
if (a[2] > a[1] + a[0])
cnt++;
}
}
}
printf("%d\n", cnt);
return 0;
}
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long int ll;
const int maxn = 500 + 50;
//const int p = 1e9 + 7;
struct node
{
int x;
int y;
};
node s[maxn];
int length(node & A, node & B)
{
return (A.x - B.x)*(A.x - B.x) + (A.y - B.y)*(A.y - B.y);//两点线段长的平方
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d%d", &s[i].x, &s[i].y);
}
int cnt = 0;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
int a[3];
a[0] = length(s[i], s[j]);//a[0]的求值放到这里就WA
for (int k = j + 1; k < n; k++){
if ((s[j].y - s[i].y)*(s[k].x - s[j].x) == (s[k].y - s[j].y)*(s[j].x - s[i].x))
continue;
//a[0]=length(s[i],s[j]);//a[0]求值放到这里就AC
a[1] = length(s[i], s[k]);
a[2] = length(s[j], s[k]);
sort(a, a + 3);
if (a[2] > a[1] + a[0])
cnt++;
}
}
}
printf("%d\n", cnt);
return 0;
}