Does this problem have some tricks?
I use the data I can find this forum,and can get the correct answer.
But when I submit this problem,always get the WA.
Does it have something to pay attention to?
my code below:
Code: Select all
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <complex>
#include <string>
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define rrep(i,j,k) for (int i=j;i>=k;--i)
#define x real()
#define y imag()
using namespace std;
const double eps = 1e-10;
const int maxn = 11111;
typedef complex<double> point;
typedef pair<point,int> pi;
pi p[maxn],ch[maxn];
int n,len,t;
string s,sx,sy;
istringstream ss,sxx,syy;
bool cmp(const pi & a,const pi & b)
{
point aa = a.first;
point bb = b.first;
return (aa.x == bb.x)?aa.y<bb.y:aa.x<bb.x;
}
int dblcmp(double k)
{
if (fabs(k) < eps) return 0;
if (k>0) return 1;
else return -1;
}
double cross(point & o,point & a,point & b)
{
point oa = a - o;
point ob = b - o;
return (oa.x * ob.y - oa.y * ob.x);
}
void andewMonotoneChain()
{
int uc,lc;
sort(p+1,p+n+1,cmp);
ch[1] = p[1];ch[uc = 2] = p[2];
rep(i,3,n)
{
while (uc > 1 &&
dblcmp(cross(ch[uc].first,ch[uc-1].first,p[i].first)) <= 0)
uc--;
ch[++uc] = p[i];
}
ch[lc = uc+1] = p[n-1];
rrep(i,n-2,1)
{
while (lc > uc &&
dblcmp(cross(ch[lc].first,ch[lc-1].first,p[i].first)) <= 0)
lc--;
ch[++lc] = p[i];
}
len = lc-1;
}
void print()
{
if (t != 1) cout << endl;
int pos,minNum = 0x7FFFFFFF/2;
rep(i,1,len)
if (ch[i].second < minNum)
{
minNum = ch[i].second;
pos = i;
}
rrep(i,pos,1) cout << ch[i].first.x << ", " << ch[i].first.y << endl;
rrep(i,len,pos) cout << ch[i].first.x << ", " << ch[i].first.y << endl;
}
int main()
{
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
ios::sync_with_stdio(false);
while (!cin.eof())
{
t++;
n = 0;
while (getline(cin,s))
{
n++;
ss.clear();
sxx.clear();
syy.clear();
ss.str(s);
getline(ss,sx,',');
getline(ss,sy);
sxx.str(sx);
syy.str(sy);
sxx >> p[n].first.x;
syy >> p[n].first.y;
//cout << sx << "!" << sy << endl;
//cout << p[n].first.x << " " << p[n].first.y << endl;
if (cin.eof()) break;
}
n--;
andewMonotoneChain();
print();
}
return 0;
}