Submission #119612

#TimeUsernameProblemLanguageResultExecution timeMemory
119612davitmargTriangles (CEOI18_tri)C++17
0 / 100
2 ms384 KiB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <fstream>
#define death
#ifndef death
#include<trilib.h>
#endif // death

#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;

#ifdef death

int get_n()
{
	int x;
	cin >> x;
	return x;
}

vector<pair<LL, LL>> point;

bool is_clockwise(int a, int b, int c)
{

}

void give_answer(int x)
{
	cout << x << endl;
}

#endif // death

map<pair<int, pair<int, int>>, bool> used, pre;

bool cw(int a, int b, int c)
{
	pair<LL, LL> A, B, C;
	A = point[a];
	B = point[b];
	C = point[c];
	return A.first * (B.second - C.second) + B.first * (C.second - A.second) + C.first * (A.second - B.second) < 0;
}

bool ccw(int a, int b, int c)
{
	pair<LL, LL> A, B, C;
	A = point[a];
	B = point[b];
	C = point[c];
	return A.first * (B.second - C.second) + B.first * (C.second - A.second) + C.first * (A.second - B.second) > 0;
}

int ans, n;
vector<int> p;


int convex(vector<int> p)
{
	vector<int> up, down;
	int st, en;

	st = p[0];
	en = p.back();

	sort(all(p), [](int a, int b) {
		if (point[a].first != point[b].first)
			return point[a].first < point[b].first;
		return point[a].second < point[b].second;
	});

	up.PB(p[0]);
	down.PB(p[0]);
	for (int i = 1; i < p.size(); i++)
	{
		if (i == p.size() - 1 || cw(st, p[i], en))
		{
			while (up.size() > 1 && !cw(up[up.size() - 2], up[up.size() - 1], p[i]))
				up.pop_back();
			up.PB(p[i]);
		}

		if (i == p.size() - 1 || ccw(st, p[i], en))
		{
			while (down.size() > 1 && !ccw(down[down.size() - 2], down[down.size() - 1], p[i]))
				down.pop_back();
			down.PB(p[i]);
		}
	}

	down.pop_back();
	reverse(all(down));
	down.pop_back();
	reverse(all(down));
	while (!down.empty())
	{
		up.PB(down.back());
		down.pop_back();
	}


	return up.size();
}

int main()
{
	n = get_n();

#ifdef death
	point.PB(MP(0, 0));
	for (int i = 0; i < n; i++)
	{
		LL x, y;
		cin >> x >> y;
		point.PB(MP(x, y));
	}
#endif // death

	for (int i = 0; i < n; i++)
		p.PB(i + 1);
	random_shuffle(all(p));
	ans = convex(p);

	give_answer(ans);

	return 0;
}


/*


4
5 10
0 0
4 3
10 0



*/

Compilation message (stderr)

tri.cpp: In function 'bool is_clockwise(int, int, int)':
tri.cpp:44:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
tri.cpp: In function 'int convex(std::vector<int>)':
tri.cpp:93:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < p.size(); i++)
                  ~~^~~~~~~~~~
tri.cpp:95:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (i == p.size() - 1 || cw(st, p[i], en))
       ~~^~~~~~~~~~~~~~~
tri.cpp:102:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (i == p.size() - 1 || ccw(st, p[i], en))
       ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...