답안 #944689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944689 2024-03-13T03:36:12 Z dugersuren Fence (CEOI08_fence) C++14
40 / 100
1 ms 460 KB
#include <bits/stdc++.h>
#define ll long long
#define MAXN 110
using namespace std;
struct TT{
    ll x,y;
};
ll n,m,dist[MAXN];
TT h[MAXN],t[MAXN],p0;
bool in[MAXN];
ll Cross(TT c,TT a,TT b){
    return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}
bool Cmp(TT a,TT b){
    return Cross(p0,a,b)>0;
}
vector<TT> ch;
void Convex_Hull(){
    ll ind=1;
    for(ll i=2;i<=n;i++){ //ind = Rigth Bottom index
        if(h[i].y<h[ind].y || (h[i].y==h[ind].y && h[i].x<h[ind].x))
            ind=i;
    }
    swap(h[1],h[ind]); //h[1] change Right Bottom tree to index=1
    p0=h[1];
    sort(h+2,h+1+n,Cmp);//Order by Angle Ox axe  
    stack<TT> s;
    s.push(h[1]);
    s.push(h[2]);
    s.push(h[3]);
    for(ll i=4;i<=n;i++){
        TT a=s.top(),b;
        s.pop();
        b=s.top();
        s.push(a);
        while(Cross(b,a,h[i])<0){
            s.pop();
            a=s.top();
            s.pop();
            b=s.top();
            s.push(a);
        }
        s.push(h[i]);
    }
    
    while (!s.empty()){
        ch.push_back(s.top());
        s.pop();
    }
    reverse(ch.begin(),ch.end());
}
vector<ll> G[MAXN];
int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for(ll i=1;i<=n;i++) cin>>h[i].x>>h[i].y; //Read holes h array
    for(ll i=1;i<=m;i++) cin>>t[i].x>>t[i].y; //Read trees t array
    Convex_Hull(); //create convex holl by h hole's array
    
    
    for(ll i=0;i<ch.size() && ch.size()>2;){//Remove free hole from "Convex holl"
    	TT a=ch[i],b=ch[(i+1)%ch.size()],c=(!i)?ch[ch.size()-1]:ch[i-1];
		bool ok=true; 
    	for(ll j=1;j<=m;j++)
    		if(Cross(a,b,t[j])>0 && Cross(b,c,t[j])>0 && Cross(c,a,t[j])>0){
    			ok=false;
    			break;
			}
		if(ok)ch.erase(ch.begin()+i);
		else i++;
	}
	
	ll ans=111*m,cnt=0;
    if (ch.size()<3){
        cout<<ans;
        return 0;
    }
    
    for(ll i=1;i<=m;i++){ //cnt=count tree in Convex holl
        in[i]=true;
        for(ll j=0;j<ch.size();j++){
            TT a=ch[j],b=t[i],c=(!j)?ch[ch.size()-1]:ch[j-1];
            in[i]=(in[i] && Cross(c,a,b)>0);
        }
        cnt+=in[i];
    }
    cout<<ch.size()*20+(m-cnt)*111;
    return 0;
}

Compilation message

fence.cpp: In function 'int main()':
fence.cpp:61:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<TT>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(ll i=0;i<ch.size() && ch.size()>2;){//Remove free hole from "Convex holl"
      |                ~^~~~~~~~~~
fence.cpp:64:6: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   64 |      for(ll j=1;j<=m;j++)
      |      ^~~
fence.cpp:69:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   69 |   if(ok)ch.erase(ch.begin()+i);
      |   ^~
fence.cpp:81:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<TT>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for(ll j=0;j<ch.size();j++){
      |                    ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -