Pagini recente » Cod sursa (job #4366) | simulareoji10 | Cod sursa (job #1560942) | Cod sursa (job #2132000) | Cod sursa (job #2530874)
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <iostream>
using namespace std;
ifstream f("gradina.in");
ofstream g("gradina.out");
struct punct
{
int x,y,poz;
};
punct v[1000];
punct a[1005],b[1005];
char afis[1005];
char aux[1005];
int n;
bool cmp(punct a,punct b)
{
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
long long sp(punct a,punct b,punct c)
{
return 1LL*(b.x-a.x)*(c.y-a.y)-1LL*(c.x-a.x)*(b.y-a.y);
}
long long int checkconvex(punct pct[],int lungime)
{
int cntstiva=0;
punct stiva[100005];
for(int i=1; i<=lungime; i++)
{
while(cntstiva>1&&sp(stiva[cntstiva-1],stiva[cntstiva],pct[i])<0)
{
cntstiva--;
}
stiva[++cntstiva]=pct[i];
}
int ccnt=cntstiva;
for(int i=lungime-1; i>=1; i--)
{
while(cntstiva>ccnt&&sp(stiva[cntstiva-1],stiva[cntstiva],pct[i])<0)
{
cntstiva--;
}
stiva[++cntstiva]=pct[i];
}
if(cntstiva-1!=lungime) return -1;
if(sp(stiva[cntstiva-2],stiva[cntstiva-1],pct[1])<0) return -1;
//stiva[++cntstiva]=pct[1];
long long arie=0;
for(int i=1;i<cntstiva;i++)
{
arie=arie+(stiva[i].x*stiva[i+1].y-stiva[i+1].x*stiva[i].y);
}
return abs(arie);
}
bool mystringcompare(char s1[],char s2[])
{
for(int i=1;i<=n;i++)
{
if(s1[i]>s2[i]) return 0;
}
return 1;
}
int main()
{
f>>n;
for(int i=1; i<=n; i++)
{
f>>v[i].x>>v[i].y;
v[i].poz=i;
}
sort(v+1,v+n+1,cmp);
checkconvex(v,n);
long long solmin=(1LL<<50);
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
int cnta=0,cntb=0;
if(i==j) continue;
for(int k=1; k<=n; k++)
{
if(k==i)
{
a[++cnta]=v[k];
aux[v[k].poz]='I';
continue;
}
if(k==j)
{
b[++cntb]=v[k];
aux[v[k].poz]='V';
continue;
}
if((sp(v[i],v[j],v[k])<0)==(i>j)) {a[++cnta]=v[k];aux[v[k].poz]='I';}
else {b[++cntb]=v[k];aux[v[k].poz]='V';}
}
if(cnta>=3&&cntb>=3)
{long long ariea=checkconvex(a,cnta);
long long arieb=checkconvex(b,cntb);
if(ariea>=0&&arieb>=0)
{long long dif=abs(ariea-arieb);
if(dif<=solmin)
{
if(dif<solmin)
{
solmin=dif;
for(int i=1; i<=n; i++)
{
afis[i]=aux[i];
}
}
else
{
if(mystringcompare(aux,afis)==1)
{
for(int i=1; i<=n; i++)
{
afis[i]=aux[i];
}
}
}
}
}
}
}
}
g<<solmin/2;
if(solmin%2==0) g<<".0";
else g<<".5";
g<<'\n';
if(afis[1]=='V'){
for(int i=1;i<=n;i++)
{
if(afis[i]=='I') g<<'V';
else g<<'I';
}
}
else
{
for(int i=1;i<=n;i++) g<<afis[i];
}
}