답안 #892095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892095 2023-12-24T21:53:35 Z StefanSebez Fence (CEOI08_fence) C++14
50 / 100
192 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
const int N=500;
const int inf=1e9;
vector<int>E[N];
struct Point{
    int x,y;
    Point(){}
    Point(int u,int v){
        x=u,y=v;
    }
};
Point operator + (Point A,Point B) {return Point(A.x+B.x,A.y+B.y);}
Point operator - (Point A,Point B) {return Point(A.x-B.x,A.y-B.y);}
int Cross(Point A,Point B) {return A.x*B.y-A.y*B.x;}
bool CW(Point A,Point B,Point C) {return Cross(A-B,C-B)>=0;}
bool CCW(Point A,Point B,Point C) {return !CW(A,B,C);}
bool operator < (Point A,Point B) {return CW(A,Point(0,0),B);}
vector<Point> ConvexHull(vector<Point> a)
{
    int n=a.size();
    int ind=0;
    for(int i=1;i<n;i++) if(a[i].y<a[ind].y || (a[i].y==a[ind].y && a[i].x<a[ind].x)) ind=i;
    Point X=a[ind];
    swap(a[0],a[ind]);
    for(int i=0;i<n;i++) a[i]=a[i]-X;
    sort(a.begin()+1,a.end());
    vector<Point>chull;
    for(int i=0;i<n;i++)
    {
        while(chull.size()>=2 && CW(chull[chull.size()-2],chull.back(),a[i])) chull.pop_back();
        chull.pb(a[i]);
    }
    for(auto &i:chull) i=i+X;
    return chull;
}
bool InPolygon(vector<Point> a,Point X){
    bool bul1=false,bul2=false;
    for(int i=0;i<a.size();i++){
        int j=i+1;if(j==a.size()) j=0;
        if(CW(X,a[i],a[j])) bul1=true;
        else bul2=true;
    }
    if(bul1 && bul2) return false;
    else return true;
}
int main()
{
    int n,m;scanf("%i%i",&n,&m);
    Point a[n+1],b[m+1];
    vector<Point>temp;
    for(int i=1;i<=n;i++) {scanf("%i %i",&a[i].x,&a[i].y);temp.pb(a[i]);}
    for(int i=1;i<=m;i++) scanf("%i %i",&b[i].x,&b[i].y);
    vector<Point>chull=ConvexHull(temp);
    vector<Point>tacke;
    for(int i=1;i<=m;i++) if(InPolygon(chull,b[i])) tacke.pb(b[i]);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(i==j) continue;
            bool bul=true;
            for(auto k:tacke) if(!CW(k,a[i],a[j])) bul=false;
            if(bul) E[j].pb(i);
        }
    }
    int res=inf;
    for(int i=1;i<=n;i++)
    {
        queue<pair<int,int> >q;
        q.push({i,0});
        bool bul=false;
        int x=inf;
        while(q.size())
        {
            int u=q.front().fi,dist=q.front().se;
            q.pop();
            if(u==i){
                if(bul){x=dist;break;}
                bul=true;
            }
            for(auto j:E[u]) q.push({j,dist+1});
        }
        res=min(res,x);
    }
    res=111*(m-tacke.size())+20*res;
    res=min(res,111*m);
    printf("%i\n",res);
    //for(auto i:chull) cout<<i.x<<" "<<i.y<<endl;
    //cout<<endl;
    return 0;
}

Compilation message

fence.cpp: In function 'bool InPolygon(std::vector<Point>, Point)':
fence.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
fence.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         int j=i+1;if(j==a.size()) j=0;
      |                      ~^~~~~~~~~~
fence.cpp: In function 'int main()':
fence.cpp:52:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     int n,m;scanf("%i%i",&n,&m);
      |             ~~~~~^~~~~~~~~~~~~~
fence.cpp:55:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     for(int i=1;i<=n;i++) {scanf("%i %i",&a[i].x,&a[i].y);temp.pb(a[i]);}
      |                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fence.cpp:56:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     for(int i=1;i<=m;i++) scanf("%i %i",&b[i].x,&b[i].y);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 192 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 130 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 155 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 124 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 166 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -