poj1288poj1228Grandpa's Estate poj1113Wall
来源:互联网 发布:淘宝买家信用有什么用 编辑:程序博客网 时间:2024/05/16 12:21
poj1288
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const double eps=1e-10;const int N=1005;inline int dcmp(int x){ if(!x) return 0; return x>0?1:-1;}struct pt{ int x,y; friend bool operator ==(pt a,pt b){ return !dcmp(a.x-b.x)&&!dcmp(a.y-b.y); }}p[N],ans[N];int s[N],cnt;inline int cross(pt a,pt b, pt c){ return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}inline bool cmp(pt a,pt b){ return (a.x<b.x)||(a.y<b.y && !dcmp(a.x-b.x));}void hull(int l,int r,pt a,pt b){ int x=l,i=l-1,j=r+1,k; for(k=l;k<=r;k++){ int tmp=dcmp(s[x]-s[k]); if(tmp<0||!tmp && cmp(p[x],p[k]))x=k; } pt y=p[x]; for(k=l;k<=r;k++){ s[++i]=cross(p[k],a,y); if(dcmp(s[i])>0)swap(p[i],p[k]); else i--; } for(k=r;k>=l;k--){ s[--j]=cross(p[k],y,b); if(dcmp(s[j])>0)swap(p[j],p[k]); else j++; } if(l<=i)hull(l,i,a,y); ans[cnt++]=y; //cout<<y.x<<' '<<y.y<<endl; if(j<=r)hull(j,r,y,b);}int main(){ int T,n,x; cin>>T; while(T--){ memset(s,0,sizeof(s)); cnt=x=0; cin>>n; for(int i=1;i<=n;i++){ scanf("%d%d",&p[i].x,&p[i].y); if(!x || cmp(p[i],p[x]))x=i; } if(n<6){cout<<"NO"<<endl;continue;} swap(p[1],p[x]); ans[cnt++]=p[1]; hull(2,n,p[1],p[1]); if(cnt<3){cout<<"NO"<<endl;continue;} //cout<<cnt<<endl; bool yes=true; for(int i=1;i<cnt&&yes;i++){ yes=false; for(int j=2;j<=n&&!yes;j++){ if(ans[i-1]==p[j] || ans[i]==p[j])continue;//sb的原来用标记函数判,wa了好几发 if(!cross(ans[i],ans[i-1],p[j])) {yes=true;//printf(" %d %d %d\n ",i,p[j].x,p[j].y); } } } if(!yes){cout<<"NO"<<endl;continue;} yes=false; for(int j=2;j<=n&&!yes;j++){ if(ans[0]==p[j] || ans[cnt-1]==p[j])continue;// if(!cross(ans[0],ans[cnt-1],p[j]))yes=true; } if(!yes)cout<<"NO"<<endl; else cout<<"YES"<<endl; } return 0;}
poj1113Wall
//˼·http://blog.csdn.net/zhengnanlee/article/details/9633357#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;const double eps =1e-10;const double pi=acos(-1.0);const int N=1005;inline int dcmp(int x){ if(!x) return 0; return x>0?1:-1;}struct pt{ int x,y;}ans[N],temp,p[N];int s[N],cnt;double sum=0;inline bool cmp(pt a,pt b){ return (a.x<b.x) || (a.y<b.y)&& !dcmp(a.x-b.x);}inline int cross(pt a,pt b,pt c){ return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}inline double dis(pt a,pt b){ return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}void hull(int l,int r,pt a,pt b){ int x=l,i=l-1,j=r+1,k; for(k=l; k<=r; k++){ int tmp=dcmp(s[x]-s[k]); if(tmp<0 || !tmp && cmp(p[x],p[k]))x=k; } pt y=p[x]; for(k=l;k<=r;k++){ s[++i]=cross(p[k],a,y); if(dcmp(s[i])>0) swap(p[i],p[k]); else i--; } for(k=r;k>=l;k--){ s[--j]=cross(p[k],y,b); if(dcmp(s[j])>0)swap(p[j],p[k]); else j++; } if(l<=i)hull(l,i,a,y); //cout<<y.x<<' '<<y.y<<endl; sum+=dis(temp,y); temp=y; //cout<<sum<<'a'<<endl; if(j<=r)hull(j,r,y,b);}int main(){ int n,l,x=0; cin>>n>>l; for(int i=1; i<=n ;i++){ scanf("%d%d",&p[i].x,&p[i].y); if(!x || cmp(p[i],p[x]))x=i; } swap(p[1],p[x]); temp=p[1]; hull(2,n,p[1],p[1]); cout<<(int)(sum+0.5+2*pi*l+dis(temp,p[1]))<<endl; return 0;}
0 0
- poj1288poj1228Grandpa's Estate poj1113Wall
- poj1113Wall
- poj1113Wall
- POJ1228 Grandpa's Estate
- pku1228 Grandpa's Estate
- pku1228Grandpa's Estate
- poj1228 - Grandpa's Estate
- POJ1228--Grandpa's Estate
- poj Grandpa's Estate
- POJ1228-Grandpa's Estate
- Grandpa's Estate
- Poj1228 Grandpa's Estate
- poj1228Grandpa's Estate
- Grandpa's Estate
- Grandpa's Estate POJ
- poj 1228 Grandpa's Estate
- POJ 1228 Grandpa's Estate
- POJ 1228 Grandpa's Estate
- 4.工厂方法模式
- 5.简单工厂模式
- 用快慢指针判断单链表环,找到环入口 扩展到判断两个链表是否相交
- Ubuntu学习笔记之apt-get命令
- 深入oracle分区索引的详解
- poj1288poj1228Grandpa's Estate poj1113Wall
- 6.代理模式
- 内向不是缺点:关于性格内向者的10个误解
- android笔记6-常用控件的介绍二
- 7.单例模式
- 8.迭代器模式
- NSNotificationCenter(通知中心)(例UIDevice通知)
- 数据库语句
- 9.访问者模式