2019ICPC南京站题解
Posted st-lovaer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2019ICPC南京站题解相关的知识,希望对你有一定的参考价值。
A题大水题。
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define f(i,a,b) for(int i=a;i<=b;i++) 4 #define scan(i) scanf("%d",&i) 5 #define pf printf 6 using namespace std; 7 8 int main() 9 { 10 int n; 11 scan(n); 12 f(i,1,n){ 13 int t; 14 scan(t); 15 if(t%2){ 16 pf("%d ",t/2+2); 17 } 18 else pf("%d ",t/2+1); 19 } 20 return 0; 21 }
H题小水题,有两个wa点,第一是只有诚实的人且人数大于1人时直接输出1,第二是只有一个人且是诚实的时输出0。
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define f(i,a,b) for(int i=a;i<=b;i++) 4 #define scan(i) scanf("%d",&i) 5 #define pf printf 6 using namespace std; 7 8 int main() 9 { 10 int a,b,c; 11 scanf("%d%d%d",&a,&b,&c); 12 if(b==0&&c==0){ 13 if(a==1){ 14 pf("YES 0"); 15 } 16 else pf("YES 1"); 17 } 18 else if(a>b+c){ 19 pf("YES %d",2*b+2*c+1); 20 } 21 else pf("NO"); 22 return 0; 23 }
K题计算几何。使用了一个假板子,发现了问题所在,已更新板子。
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define f(i,a,b) for(int i=a;i<=b;i++) 4 #define scan(i) scanf("%d",&i) 5 #define pf printf 6 using namespace std; 7 const double eps=1e-10; 8 const double PI=acos(-1.0); 9 using namespace std; 10 struct Point{ 11 double x; 12 double y; 13 Point(double x=0,double y=0):x(x),y(y){} 14 void operator<<(Point &A) {cout<<A.x<<‘ ‘<<A.y<<endl;} 15 bool operator!=(Point &A) {if(fabs(A.x-x)>eps||fabs(A.y-y)>eps) return true;return false;} 16 }; 17 18 int dcmp(double x) {return (x>eps)-(x<-eps); } 19 int sgn(double x) {return (x>eps)-(x<-eps); } 20 typedef Point Vector; 21 22 Vector operator +(Vector A,Vector B) { return Vector(A.x+B.x,A.y+B.y);} 23 Vector operator -(Vector A,Vector B) { return Vector(A.x-B.x,A.y-B.y); } 24 Vector operator *(Vector A,double p) { return Vector(A.x*p,A.y*p); } 25 Vector operator /(Vector A,double p) {return Vector(A.x/p,A.y/p);} 26 ostream &operator<<(ostream & out,Point & P) { out<<P.x<<‘ ‘<<P.y<<endl; return out;} 27 bool operator< (const Point &A,const Point &B) { return dcmp(A.x-B.x)<0||(dcmp(A.x-B.x)==0&&dcmp(A.y-B.y)<0); } 28 bool operator== ( const Point &A,const Point &B) { return dcmp(A.x-B.x)==0&&dcmp(A.y-B.y)==0;} 29 30 double Dot(Vector A,Vector B) {return A.x*B.x+A.y*B.y;} 31 double Cross(Vector A,Vector B) {return A.x*B.y-B.x*A.y; } 32 double Length(Vector A) { return sqrt(Dot(A, A));} 33 double Angle(Vector A,Vector B) {return acos(Dot(A,B)/Length(A)/Length(B));} 34 double Area2(Point A,Point B,Point C ) {return fabs(Cross(B-A, C-A));} 35 36 Vector Rotate(Vector A,double rad) { return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));} 37 Vector Normal(Vector A) {double L=Length(A);return Vector(-A.y/L,A.x/L);} 38 39 Point GetLineIntersection(Point P,Vector v,Point Q,Vector w){ 40 if(v.x*w.y==v.y*w.x) return Point(5201314,5201314); 41 Vector u=P-Q; 42 double t=Cross(w, u)/Cross(v,w); 43 return P+v*t; 44 }//输入两个点斜式方程输出交点 45 46 bool OnSegment(Point P,Point A,Point B){ 47 return dcmp(Cross(P-A, P-B))==0&&dcmp(Dot(P-A,P-B))<=0; 48 }//输入三个点,判断P是否在线段AB上 49 50 double x1,x2,x3,x4,y11,y2,y3,y4; 51 int main() 52 { 53 int T; 54 scan(T); 55 f(kk,1,T){ 56 scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y11,&x2,&y2,&x3,&y3,&x4,&y4); 57 Point a(x1,y11),b(x2,y2),c(x3,y3),p(x4,y4); 58 int x=0; 59 if(OnSegment(p,a,b)) x=1; 60 else if(OnSegment(p,a,c)) x=2; 61 else if(OnSegment(p,b,c)) x=3; 62 if(x==0) pf("-1 "); 63 else{ 64 double area=Area2(a,b,c)/2; 65 if(x==2) swap(b,c); 66 else if(x==3) swap(a,c); 67 if(Length(p-a)>Length(p-b)){ 68 double angle=Angle(a-b,a-c); 69 //area*0.5=0.5*a*b*sinx; 70 double k=area/sin(angle)/Length(p-a)/Length(c-a); 71 //cout<<k<<endl; 72 Point ans=(c-a)*k+a; 73 pf("%.10lf %.10lf ",ans.x,ans.y); 74 } 75 else{ 76 double angle=Angle(b-a,b-c); 77 //area*0.5=0.5*a*b*sinx; 78 double k=area/sin(angle)/Length(p-b)/Length(c-b); 79 //cout<<k<<endl; 80 Point ans=(c-b)*k+b; 81 pf("%.10lf %.10lf ",ans.x,ans.y); 82 } 83 } 84 } 85 }
以上是关于2019ICPC南京站题解的主要内容,如果未能解决你的问题,请参考以下文章
The Preliminary Contest for ICPC Asia Nanjing 2019/2019南京网络赛——题解