QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#511383#7906. Almost ConvexJEdwardCompile Error//C++172.6kb2024-08-09 20:14:442024-08-09 20:14:44

Judging History

你现在查看的是最新测评结果

  • [2024-08-09 20:14:44]
  • 评测
  • [2024-08-09 20:14:44]
  • 提交

answer

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define int long long
#define endl '\n'
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define ls(x) (x<<1)
#define rs(x) (x<<1|1) 
#define here system("pause")
using namespace std;
template <class T> inline void read(T& x) { x = 0; char c = getchar(); bool f = 0; for (; !isdigit(c); c = getchar()) f ^= (c == '-'); for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); x = f ? -x : x; }
template <class T> inline void write(T x) { if (x < 0) putchar('-'), x = -x; if (x < 10) putchar(x + 48); else write(x / 10), putchar(x % 10 + 48); }

const int N = 4e3+5;
const int mod = 1e9+7;
const int INF = 8e18+7;
const double eps = 1e-6;
inline int pow(int a, int b, int p){ int res = 1%p; while(b){ if(b&1) res=res*a%p; a=a*a%p, b>>=1;} return res;}
inline int inv(int a, int p){ return pow(a,p-2,p)%p;}

struct Point{
	int x, y;
	int idx;
	int ok(){
		return x>0 || x==0 && y>0;
	}
};
Point operator + (const Point &a, const Point &b){
	return {a.x + b.x, a.y + b.y, 0};
}
Point operator - (const Point &a, const Point &b){
	return {a.x - b.x, a.y - b.y, 0};
}
inline int Cross(Point a, Point b){ return a.x * b.y - a.y * b.x; }

sint n;
Point a[N], s[N];
bool vis[N];

inline void sol(){
	cin >> n;
	for(int i=1;i<=n;i++){
		int x, y;
		cin >> x >> y;
		a[i] = {x, y, 0};
	}
	sort(a+1, a+1+n, [&](const Point &lhs, const Point &rhs){
		return lhs.x == rhs.x ? lhs.y < rhs.y : lhs.x < rhs.x;
	});
	for(int i=1;i<=n;i++){
		a[i].idx = i;
	}
	
	int Top = 0;
	for(int i=1;i<=n;i++){
		while(Top > 1 && Cross(s[Top] - s[Top-1], a[i] - s[Top]) < 0){
			--Top;
		}
		s[++Top] = a[i];
	}
	
	int K = Top;
	for(int i=n-1;i;i--){
		while(Top > K && Cross(s[Top] - s[Top-1], a[i] - s[Top]) <= 0){
			--Top;
		}
		s[++Top] = a[i];
	}
	
	for(int i=1;i<Top;i++) vis[s[i].idx] = 1;
	
	int ans = 1;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			vector<Point> c;
			for(int j=1;j<Top;j++){
				Point x = s[j] - a[i];
				x.idx = 1;
				c.push_back(x);
			}
			for(int j=1;j<=n;j++){
				if((i^j) && !vis[j]){
					c.push_back(a[j] - a[i]);
				}
			}
			sort(all(c), [&](Point &lhs, Point &rhs){
				return lhs.ok() == rhs.ok() ? Cross(lhs, rhs) > 0 : lhs.ok() < rhs.ok();
			});
			
			for(int j=0;j+1<c.size();j++){
				if(c[j].idx && c[j+1].idx) ++ans;
			}
			if(c[0].idx && c.back().idx) ++ans;
		}
	}
	cout << ans << endl;
}

signed main(){
	IOS;
	int tc = 1;
//	cin >> tc;
	while(tc--){
		sol();
	}
	return 0;
}

Details

answer.code:37:1: error: ‘sint’ does not name a type; did you mean ‘uint’?
   37 | sint n;
      | ^~~~
      | uint
answer.code: In function ‘void sol()’:
answer.code:42:16: error: ‘n’ was not declared in this scope
   42 |         cin >> n;
      |                ^