2019-2020 ICPC Asia Taipei-Hsinchu Regional Contest 训练记录
Posted uuzhateteee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2019-2020 ICPC Asia Taipei-Hsinchu Regional Contest 训练记录相关的知识,希望对你有一定的参考价值。
solved:9/13
upsolved:9/13
C.
签到题
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n; 4 int a[55]; 5 int main() 6 { 7 scanf("%d",&n); 8 for(int i=1;i<=n;++i)scanf("%d",&a[i]); 9 bool yes=1; 10 for(int i=1;i<=n;++i) 11 for(int j=1;j<=n;++j)if(j!=i) 12 for(int k=1;k<=n;++k)if(k!=i&&k!=j) 13 { 14 int x=abs(a[i]-a[j]); 15 if(x%a[k])yes=0; 16 } 17 if(yes)puts("yes"); 18 else puts("no"); 19 }
D.
签到题
1 #include<bits/stdc++.h> 2 using namespace std; 3 string s; 4 int main() 5 { 6 bool has=0; 7 while(cin>>s) 8 { 9 if(s=="bubble"||s=="tapioka")continue; 10 has=1; 11 cout<<s<<" "; 12 } 13 if(!has)puts("nothing"); 14 }
E.
构造一个长度1999的序列
考虑第一个数是负数,那么假算法一定不会包含这个数,取(a_1=-1)
序列为(-1,a_2,a_3,…,a_{1999})
那么假算法的解为(1998*sum_{i=2}^{1999}{a_i})
真算法的解为(1999*(sum_{i=2}^{1999}{a_i}-1))
那么假算法的解比真算法小$k$,则有(1999*(sum_{i=2}^{1999}{a_i}-1)=1998*sum_{i=2}^{1999}{a_i}+k)
则有(sum_{i=2}^{1999}{a_i}=1999+k)
随便构造一下凑够(k)就完事了
1 #include<bits/stdc++.h> 2 using namespace std; 3 int T,k,L; 4 int main() 5 { 6 scanf("%d",&T); 7 while(T--) 8 { 9 scanf("%d%d",&k,&L); 10 if(L>=2000)puts("-1"); 11 else 12 { 13 puts("1999"); 14 printf("-1 "); 15 int s=k+1999,x=1000000; 16 for(int i=1;i<=1998;++i) 17 { 18 if(s>=x) 19 { 20 printf("%d ",x); 21 s-=x; 22 } 23 else 24 { 25 printf("%d ",s); 26 s=0; 27 } 28 } 29 } 30 } 31 }
H.
考虑方程(frac{1}{x}+frac{1}{y}=frac{1}{n})
移项通分有(frac{1}{y}=frac{x-n}{xn})
则(y=frac{xn}{x-n})
令(a=x-n),则有(y=n+frac{n^2}{a})
那么枚举(n^2)的约数,解出(x,y)即可
然后(a=x oplus y)
1 #include<bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 int T; 5 ll n; 6 int main() 7 { 8 cin>>T; 9 while(T--) 10 { 11 cin>>n; 12 ll ans=0; 13 for(ll i=1;i<=n;++i)if((n*n)%i==0) 14 { 15 ll y=n+n*n/i; 16 ll x=n+i; 17 ll a=x^y; 18 ans=max(ans,a); 19 } 20 cout<<ans<<endl; 21 } 22 }
J.
二进制枚举集合,签到题
1 #include<bits/stdc++.h> 2 using namespace std; 3 int T,n,m; 4 bitset<505> a[18]; 5 int main() 6 { 7 scanf("%d",&T); 8 while(T--) 9 { 10 scanf("%d%d",&n,&m); 11 for(int i=0;i<m;++i) 12 { 13 char str[505]; 14 scanf("%s",str); 15 for(int j=0;j<n;++j)a[i][j]=0; 16 for(int j=0;j<n;++j)if(str[j]==‘1‘)a[i][j]=1; 17 } 18 int ans=m+1; 19 for(int S=0;S<(1<<m);++S) 20 { 21 bitset<505> b; 22 for(int i=0;i<n;++i)b[i]=0; 23 int cnt=0; 24 for(int i=0;i<m;++i)if(S&(1<<i))b|=a[i],cnt++; 25 bool yes=1; 26 for(int i=0;i<n;++i)if(!b[i])yes=0; 27 if(yes)ans=min(ans,cnt); 28 } 29 if(ans<=m)printf("%d ",ans); 30 else puts("-1"); 31 } 32 }
L.
因为可能是退化的四边形,所以不能在凸包上直接找点
考虑四边形的对角线一定是凸包上的对踵点,那么这步可以旋转卡壳得到对踵点
我们下面不能直接在凸包上三分了,但本题允许(O(n^2))的时间复杂度,那么我们枚举点
四边形可能是凹的,所以我们枚举的时候需要分别记录这条线两边最大最小的面积
如果某边没有点,就是最大减最小,否则就是两边相加
1 #include<bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 struct Point 5 { 6 ll x,y; 7 Point(ll X=0,ll Y=0):x(X),y(Y){} 8 }; 9 typedef Point Vector; 10 inline Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);} 11 inline Vector operator - (Point A,Point B){return Vector(A.x-B.x, A.y-B.y);} 12 ll Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;} 13 bool operator < (Point A,Point B){if(A.x==B.x)return A.y<B.y;return A.x<B.x;} 14 bool operator == (Point A,Point B){return (A.x==B.x)&&(A.y==B.y);} 15 vector<Point> ConvexHull(vector<Point>& p) 16 { 17 sort(p.begin(),p.end()); 18 p.erase(unique(p.begin(),p.end()),p.end()); 19 int n=p.size(); 20 int m=0; 21 vector<Point> ch(n+1); 22 for(int i=0;i<n;++i) 23 { 24 while(m>1&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--; 25 ch[m++]=p[i]; 26 } 27 int k=m; 28 for(int i=n-2;i>=0;--i) 29 { 30 while(m>k&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--; 31 ch[m++]=p[i]; 32 } 33 if(n>1)m--; 34 ch.resize(m); 35 return ch; 36 } 37 int T,n,m; 38 vector<Point> A,H; 39 ll calc(Point U,Point V,bool tst=0) 40 { 41 bool firU=0,firV=0; 42 vector<Point> B;B.clear(); 43 for(Point p:A) 44 { 45 if(p==U&&(!firU))firU=1; 46 else if(p==V&&(!firV))firV=1; 47 else B.push_back(p); 48 } 49 ll mx1=-1,mx2=-1,mn1=(ll)2e18,mn2=(ll)2e18; 50 for(Point p:B) 51 { 52 //if(tst)printf("(%I64d,%I64d) ",p.x,p.y); 53 if(Cross(V-U,p-U)<0) 54 { 55 mx1=max(mx1,abs(Cross(V-U,p-U))); 56 mn1=min(mn1,abs(Cross(V-U,p-U))); 57 } 58 else 59 { 60 mx2=max(mx2,abs(Cross(V-U,p-U))); 61 mn2=min(mn2,abs(Cross(V-U,p-U))); 62 } 63 } 64 if(mx1==-1)return mx2-mn2; 65 else if(mx2==-1)return mx1-mn1; 66 else return mx1+mx2; 67 } 68 int main() 69 { 70 scanf("%d",&T); 71 while(T--) 72 { 73 A.clear(); 74 scanf("%d",&n); 75 for(int i=1;i<=n;++i) 76 { 77 ll x,y; 78 scanf("%I64d%I64d",&x,&y); 79 A.push_back(Point(x,y)); 80 } 81 H=A; 82 H=ConvexHull(H); 83 m=H.size(); 84 if(m<=2) 85 { 86 puts("0"); 87 continue; 88 } 89 int j=1; 90 ll ans=0; 91 for(int i=0;i<m;++i) 92 { 93 while(abs(Cross(H[j]-H[i],H[j]-H[(i+1)%m]))<abs(Cross(H[(j+1)%m]-H[i],H[(j+1)%m]-H[(i+1)%m])))j=(j+1)%m; 94 ans=max(ans,calc(H[i],H[j])); 95 } 96 if(ans&1)printf("%I64d.5 ",ans/2); 97 else printf("%I64d ",ans/2); 98 } 99 }
以上是关于2019-2020 ICPC Asia Taipei-Hsinchu Regional Contest 训练记录的主要内容,如果未能解决你的问题,请参考以下文章
2019-2020 ICPC, Asia Jakarta Regional Contest H. Twin Buildings
比赛:ICPC Asia Taipei-Hsinchu Regional 2019 2020.4.1
2019-2020 ICPC Asia Taipei-Hsinchu Regional Contest 训练记录
2019-2020 ICPC, Asia Jakarta Regional Contest.E. Songwriter
2019-2020 ICPC, Asia Jakarta Regional Contest K题 Addition Robot线段树维护矩阵积