QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643155#5426. Drain the Water TankChensenCHXCompile Error//C++231.6kb2024-10-15 19:20:092024-10-15 19:20:11

Judging History

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

  • [2024-10-15 19:20:11]
  • 评测
  • [2024-10-15 19:20:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long
const int N = 2e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int,int>PII;
const double eps = 1e-6;

int sign(double x){
	if(fabs(x) < eps) return 0;
	if(x > 0) return 1;
	return -1;
}

struct point{
	double x , y;
	point(){}
	point(double a , double b) : x(a) , y(b){}
}; 

double det(const point &a , const point &b){
	return a.x * b.y - a.y * b.x;
}

double toleft(point p , point a, point b) {
    point A = point(b.x - a.x , b.y - a.y); //向量ab
    point B = point(p.x - a.x , p.y - a.y); //向量ap
    return det(A , B);
}

int n;
point p[N];

inline nex(int x){ return (x + 1) % n; }
inline pre(int x){ return (x - 1 + n) % n; }

signed main(){

	cin >> n;
	for(int i = 0 ; i < n ; i ++){
		double x , y;cin >> x >> y;
		p[i] = point{x , y};
	}
	
	point xx , yy;
	
	int res = 0;
	
	for(int i = 0 ; i < n ; i ++){
		
		if(p[i].y == p[nex(i)].y) continue;
		
		bool tagp = 0 , tagn = 0;
		
		for(int j = pre(i) ; j != i ; j = pre(j)){
			if(p[j].y == p[i].y) continue;
			if(p[j].y >  p[i].y) {
				xx = p[j];
				tagp = 1;
				break;
			}
			if(p[j].y <  p[i].y) break;
		}
		for(int j = nex(i) ; j != i ; j = nex(j)){
			if(p[j].y == p[i].y) continue;
			if(p[j].y >  p[i].y) {
				yy = p[j];
				tagn = 1;
				break;
			}
			if(p[j].y <  p[i].y) break;
		}
		if(!tagp || !tagn) continue;
		
		if(p[i].y == p[pre(i)].y){
			if(p[i].x > p[pre(i)].x) res += 1;
		}else{
			if(sign(toleft(p[pre(i)] , p[i] , p[nex(i)])) == 1) res += 1;
		}
	}

	cout << res << "\n";

	return 0;
}

Details

answer.code:36:8: error: ISO C++ forbids declaration of ‘nex’ with no type [-fpermissive]
   36 | inline nex(int x){ return (x + 1) % n; }
      |        ^~~
answer.code:37:8: error: ISO C++ forbids declaration of ‘pre’ with no type [-fpermissive]
   37 | inline pre(int x){ return (x - 1 + n) % n; }
      |        ^~~