#include <bits/stdc++.h>
using namespace std;
struct Punct
{
long long x,y;
};
long long determinant (Punct a,Punct b,Punct c)
{
return a.x*b.y+b.x*c.y+a.y*c.x-a.y*b.x-b.y*c.x-a.x*c.y;
}
bool compare (Punct a, Punct b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
int n,i,st[4005],q,viz[4005];
Punct v[1005];
struct Triangle
{
int a,b,c;
};
int ok[1005],primul;
vector <Triangle> triunghiuri;
long long ABS(long long x)
{
if (x>0)
{
return x;
}
return -x;
}
bool seinter(pair <Punct,Punct> dreapta1,pair <Punct,Punct> dreapta2)
{
if (1LL*determinant(dreapta1.first,dreapta1.second,dreapta2.first)*determinant(dreapta1.first,dreapta1.second,dreapta2.second)>=0)
{
return 0;
}
if (1LL*determinant(dreapta2.first,dreapta2.second,dreapta1.first)*determinant(dreapta2.first,dreapta2.second,dreapta1.second)>=0)
{
return 0;
}
return 1;
}
int Marc[1005][1005],j;
vector <pair <int,int>> candidati;
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(0);
#ifdef HOME
ifstream cin("date.in");
ofstream cout("date.out");
#endif // HOME
cin>>n;
for (i=1; i<=n; i++)
{
cin>>v[i].x>>v[i].y;
}
sort (v+1,v+n+1,compare);
st[++q]=1;
st[++q]=2;
viz[1]=viz[2]=1;
for (i=3; i<=n; i++)
{
while (q>1&&determinant(v[st[q-1]],v[st[q]],v[i])<0)
{
viz[st[q]]=0;
q--;
}
viz[i]=1;
st[++q]=i;
}
for (i=n; i>=1; i--)
{
if (viz[i]==0)
{
while (q>1&&determinant(v[st[q-1]],v[st[q]],v[i])<0)
{
viz[st[q]]=0;
q--;
}
viz[i]=1;
st[++q]=i;
}
}
while (q>1&&determinant(v[st[q-1]],v[st[q]],v[1])<0)
{
q--;
}
for (i=1; i<=q; i++)
{
ok[st[i]]=1;
}
for (i=1; i<=n; i++)
{
if (ok[i]==0)
{
primul= i ;
break;
}
}
ok[primul]=1;
for (i=1; i<q; i++)
{
triunghiuri.push_back({st[i],st[i+1],primul});
}
triunghiuri.push_back({st[1],st[q],primul});
for (i=1; i<=n; i++)
{
if (ok[i]==0)
{
int loc=0;
for (int j=0; j<triunghiuri.size(); j++)
{
int x=triunghiuri[j].a,y=triunghiuri[j].b,z=triunghiuri[j].c;
int val1 = ABS(determinant(v[x],v[y],v[i]));
int val2 = ABS(determinant(v[y],v[z],v[i]));
int val3 = ABS(determinant(v[z],v[x],v[i]));
int valfin = ABS(determinant(v[x],v[y],v[z]));
if (val1+val2+val3==valfin)
{
loc = j;
break;
}
}
Triangle triunghi1= {triunghiuri[loc].a,triunghiuri[loc].b,i};
Triangle triunghi2= {triunghiuri[loc].a,triunghiuri[loc].c,i};
Triangle triunghi3= {triunghiuri[loc].b,triunghiuri[loc].c,i};
triunghiuri.erase(triunghiuri.begin()+loc);
triunghiuri.push_back(triunghi1);
triunghiuri.push_back(triunghi2);
triunghiuri.push_back(triunghi3);
}
}
for (int j=0; j<triunghiuri.size(); j++)
{
int x=triunghiuri[j].a,y=triunghiuri[j].b,z=triunghiuri[j].c;
Marc[x][y]=Marc[y][x]=Marc[x][z]=Marc[z][x]=Marc[z][y]=Marc[y][z]=1;
}
for (i=1; i<=n; i++)
{
for (j=i+1; j<=n; j++)
{
if (Marc[i][j])
{
candidati.push_back({i,j});
}
}
}
int sum=0;
for (i=0; i<candidati.size(); i++)
{
int ok1=1;
for (j=1; j<=n; j++)
{
for (int k=j+1; k<=n; k++)
{
if (seinter({v[candidati[i].first],v[candidati[i].second]}, {v[j],v[k]}))
{
ok1=0;
break;
}
}
if (ok1==0)
{
break;
}
}
sum=sum+ok1;
}
cout<<sum;
return 0;
}
Compilation message
geometrija.cpp: In function 'int main()':
geometrija.cpp:113:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Triangle>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for (int j=0; j<triunghiuri.size(); j++)
| ~^~~~~~~~~~~~~~~~~~~
geometrija.cpp:135:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Triangle>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for (int j=0; j<triunghiuri.size(); j++)
| ~^~~~~~~~~~~~~~~~~~~
geometrija.cpp:151:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
151 | for (i=0; i<candidati.size(); i++)
| ~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |