QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#649315#5426. Drain the Water TankONISINOWA 1ms3844kbC++202.1kb2024-10-17 22:45:032024-10-17 22:45:04

Judging History

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

  • [2024-10-17 22:45:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3844kb
  • [2024-10-17 22:45:03]
  • 提交

answer

#include <bits/stdc++.h>

//DEBUG:    https://github.com/sharkdp/dbg-macro
#ifdef LOCAL
#include "../dbg-macro-0.5.1/dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif

#define endl '\n'
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef long double llf;
const ll MAXN=2e5+10,MOD=998244353,INF=1e9;

ll qpow(ll base,ll exp){ll ans=1;while(exp){if(exp&1)(ans*=base)%=MOD;(base*=base)%=MOD;exp>>=1;}return ans;}
template<class T>ll max_binary_answer(ll l,ll r,T check,bool cmp=true){ll m;while(l<r){m=(l+r+1)/2;if(cmp^!check(m))l=m;else r=m-1;}return l;}
template<class T>ll min_binary_answer(ll l,ll r,T check,bool cmp=true){ll m;while(l<r){m=(l+r)/2;if(cmp^!check(m))r=m;else l=m+1;}return r;}
ll exgcd(ll a,ll b,ll &x,ll &y){ll tmp;return b==0?(x=1,y=0,a):(tmp=exgcd(b,a%b,y,x),y-=(a/b)*x,tmp);}
ll highbit(ll x){for(ll i=1;i<(ll)sizeof(ll)*4;i<<=1)x|=x>>i;return x-(x>>1);}
ll lowbit(ll x){return x&(-x);}
//--------Global declared area--------
ll cross(pair<ll,ll> x,pair<ll,ll> y,pair<ll,ll> z){
	//x1*y2-x2*y1
	return (x.first-y.first)*(z.second-y.second)-(z.first-y.first)*(x.second-y.second);
}
void p(pair<ll,ll> x){
	cout<<x.first<<','<<x.second<<endl;
}
//--------Global declared end --------
void solve(int test_num){
	int n,ans=1;
	cin>>n;
	vector<pair<ll,ll>> a(2*n);
	for(int i=0;i<n;i++){
		cin>>a[i].first>>a[i].second;
		a[i+n]=a[i];
	}
	int l=0,r=0;
	while(a[l].second==a[(l-1+n)%n].second){
		l=(l-1+n)%n;
	}
	
	while(r<n){
		while(a[r].second==a[(r+1)%n].second&&r<n){
			r=r+1;
		}
		if(r>=n){
			break;
		}
		ll tmp1=cross(a[(l-1+n)%n],a[r],a[(r+1)%n]);
		ll tmp2=cross(a[(l-1+n)%n],a[l],a[(r+1)%n]);
		if(a[(l-1+n)%n].second<a[l].second&&a[(r+1)%n].second<a[r].second&&a[l].first<=a[r].first){
			ans++;
//			cout<<"l r: "<<l<<' '<<r<<endl;
//			p(a[l]);
//			p(a[r]); 
		}
		l=r=r+1;
	}
	cout<<ans<<endl;
}

int main(){
	//std::ios::sync_with_stdio(false);
	//std::cin.tie(nullptr),std::cout.tie(nullptr);
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){
		solve(i);
		//cout.flush();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3604kb

input:

6
0 0
1 1
2 1
3 0
3 2
0 2

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

8
4 4
0 4
0 2
1 2
2 2
2 0
3 0
4 0

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3588kb

input:

7
1 0
3 4
0 3
1 2
2 3
1 1
0 2

output:

4

result:

wrong answer 1st numbers differ - expected: '2', found: '4'