gym 101628
Posted mxang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gym 101628相关的知识,希望对你有一定的参考价值。
前几天感冒了三天没怎么写题。。。今天好很多了打个三星场找点手感。
不行啊我好菜啊。只会8个。。补题的话,再说吧。G题感觉值得一补。
说实话这个三星场还是很新人向的,知识点也蛮多(
A:
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const ll mod = 1e9+7; 5 string s,t; 6 ll ans[11]; 7 int main(){ 8 ios::sync_with_stdio(false); 9 cin>>s>>t; 10 int n=s.length(),m=t.length(); 11 s="*"+s;t="*"+t; 12 ans[0]=1; 13 for(int i=1;i<=n;i++){ 14 for(int j=m;j>=1;j--){ 15 if(s[i]==t[j]){ 16 ans[j]=(ans[j]+ans[j-1])%mod; 17 } 18 } 19 } 20 cout<<ans[m]<<endl; 21 }
B:咕咕咕
C:援圆交,注意两圆相切
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef double db; 4 const db eps=1e-8; 5 const db pi=acos(-1); 6 int sign(db k){ 7 if (k>eps) return 1; else if (k<-eps) return -1; return 0; 8 } 9 int cmp(db k1,db k2){return sign(k1-k2);} 10 struct point{ 11 db x,y; 12 point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};} 13 point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};} 14 point operator * (db k1) const{return (point){x*k1,y*k1};} 15 point operator / (db k1) const{return (point){x/k1,y/k1};} 16 int operator == (const point &k1) const{return cmp(x,k1.x)==0&&cmp(y,k1.y)==0;} 17 bool operator < (const point k1) const{ 18 int a=cmp(x,k1.x); 19 if (a==-1) return 1; else if (a==1) return 0; else return cmp(y,k1.y)==-1; 20 } 21 db abs(){return sqrt(x*x+y*y);} 22 db abs2(){return x*x+y*y;} 23 point turn(db k1){return (point){x*cos(k1)-y*sin(k1),x*sin(k1)+y*cos(k1)};} 24 point turn90(){return (point){-y,x};} 25 point unit(){db w=abs(); return (point){x/w,y/w};} 26 db dis(point k1){return ((*this)-k1).abs();} 27 void print(){printf("%.11lf %.11lf ",x,y);} 28 }; 29 struct circle{ 30 point o;db r; 31 int inside(point k){return cmp(r,o.dis(k));} 32 }; 33 int checkposCC(circle k1,circle k2){// 返回两个圆的公切线数量 34 if (cmp(k1.r,k2.r)==-1) swap(k1,k2); 35 db dis=k1.o.dis(k2.o); int w1=cmp(dis,k1.r+k2.r),w2=cmp(dis,k1.r-k2.r); 36 if (w1>0) return 4; else if (w1==0) return 3; else if (w2>0) return 2; 37 else if (w2==0) return 1; else return 0; 38 } 39 vector<point> getCC(circle k1,circle k2){// 沿圆 k1 逆时针给出 , 相切给出两个 40 int pd=checkposCC(k1,k2); if (pd==0||pd==4) return {}; 41 db a=(k2.o-k1.o).abs2(),cosA=(k1.r*k1.r+a-k2.r*k2.r)/(2*k1.r*sqrt(max(a,(db)0.0))); 42 db b=k1.r*cosA,c=sqrt(max((db)0.0,k1.r*k1.r-b*b)); 43 point k=(k2.o-k1.o).unit(),m=k1.o+k*b,del=k.turn90()*c; 44 return {m-del,m+del}; 45 } 46 point a,b;db d; 47 set<point>st; 48 int main(){ 49 //db delta = rand()/65536; 50 scanf("%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&d); 51 //a.turn(delta),b.turn(delta); 52 circle x = {a,d},y={b,a.dis(b)}; 53 vector<point> s = getCC(x,y); 54 if(s.empty()){ 55 printf("NO "); 56 }else{ 57 for(auto tmp:s){ 58 st.insert(tmp); 59 } 60 if(st.size()==1){ 61 printf("NO "); 62 return 0; 63 } 64 printf("YES "); 65 for(auto tmp:st){ 66 tmp.print(); 67 } 68 } 69 }
D:被这题烦死了。
1 #include <bits/stdc++.h> 2 using namespace std; 3 int n,m,t;char p[2]; 4 int main(){ 5 scanf("%d%d%d",&n,&m,&t); 6 int mx1=0,mn1=0,mx2=0,mn2=0,x=0,y=0; 7 for(int i=1;i<=t;i++){ 8 scanf("%s",p); 9 if(p[0]==‘D‘){ 10 y++; 11 }else if(p[0]==‘B‘){ 12 x--; 13 }else if(p[0]==‘C‘){ 14 x++; 15 }else if(p[0]==‘E‘){ 16 y--; 17 } 18 mx1=max(mx1,x); 19 mn1=min(mn1,x); 20 mx2=max(mx2,y); 21 mn2=min(mn2,y); 22 } 23 int h=mx2-mn2+1,w=mx1-mn1+1; 24 h=m-h,w=n-w; 25 x-=mn1,y-=mn2; 26 printf("%d ",(w+1)*(h+1)); 27 for(int i=x;i<=x+w;i++){ 28 for(int j=y;j<=y+h;j++){ 29 printf("%d %d ",i+1,j+1); 30 } 31 } 32 }
E:哇根本不可做啊!!!被治了四个小时啊。
1 #include <bits/stdc++.h> 2 using namespace std; 3 int dp[3003][3003]; 4 char s[3005];int k; 5 int main(){ 6 scanf("%s%d",s+1,&k); 7 int n = strlen(s+1); 8 for(int l=1;l<=n;l++){ 9 for(int i=1;i<=n;i++){ 10 if(i+l>n)break; 11 dp[i][i+l]=dp[i+1][i+l-1]+(s[i]==s[i+l]?0:1); 12 } 13 } 14 int ans = 0; 15 for(int i=1;i<=n;i++){ 16 for(int j=i;j<=n;j++){ 17 if(dp[i][j]<=k) 18 ans++; 19 } 20 } 21 printf("%d ",ans); 22 }
F:最短路
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N = 3e4+5; 5 struct Edge{int v;ll w;int nxt;}; 6 Edge e[100005]; 7 int head[N],cnt=0; 8 void addEdge(int u,int v,ll w){ 9 e[++cnt].v=v; 10 e[cnt].w=w; 11 e[cnt].nxt=head[u]; 12 head[u]=cnt; 13 } 14 int n,c,m; 15 ll dis[N]; 16 struct node{ 17 ll u,d; 18 bool operator <(const node&rhs) const{ 19 return d>rhs.d; 20 } 21 }; 22 void Dijkstra(){ 23 for(int i=1;i<=n;i++)dis[i]=1e18; 24 dis[1]=0; 25 priority_queue<node> Q; 26 Q.push((node){1,0}); 27 while (!Q.empty()){ 28 node fr = Q.top();Q.pop(); 29 ll u = fr.u,d=fr.d; 30 if(d>dis[u])continue; 31 for(int i=head[u];i;i=e[i].nxt){ 32 ll v=e[i].v,w=e[i].w; 33 if(dis[u]+w<dis[v]) { 34 dis[v] = dis[u] + w; 35 Q.push((node) {v, dis[v]}); 36 } 37 } 38 } 39 } 40 ll t,k,p,vis[N],x,y,z; 41 int main(){ 42 ios::sync_with_stdio(false); 43 cin>>n>>m>>t>>k>>p; 44 for(int i=1;i<=p;i++){ 45 cin>>x;vis[x]=1; 46 } 47 for(int i=1;i<=m;i++){ 48 cin>>x>>y>>z; 49 if(vis[y])addEdge(x,y,z*60+k); 50 else addEdge(x,y,z*60); 51 } 52 Dijkstra(); 53 if(dis[n]<=t*60){ 54 cout<<dis[n]<<endl; 55 }else{ 56 cout<<-1<<endl; 57 } 58 }
G:没看懂样例。
H:又一个最短路。。
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 1e5+5; 4 struct Edge{int v,w,nxt;}; 5 Edge e[N*2]; 6 int head[N],cnt=0; 7 void addEdge(int u,int v,int w){ 8 e[++cnt].v=v; 9 e[cnt].w=w; 10 e[cnt].nxt=head[u]; 11 head[u]=cnt; 12 } 13 int n,c,m; 14 int dis[N],vis[N]; 15 struct node{ 16 int u,d; 17 bool operator <(const node&rhs) const{ 18 return d>rhs.d; 19 } 20 }; 21 void Dijkstra(){ 22 for(int i=1;i<=n;i++)dis[i]=1e8; 23 dis[1]=vis[1]; 24 priority_queue<node> Q; 25 Q.push((node){1,vis[1]}); 26 while (!Q.empty()){ 27 node fr = Q.top();Q.pop(); 28 int u = fr.u,d=fr.d; 29 if(d>dis[u])continue; 30 for(int i=head[u];i;i=e[i].nxt){ 31 int v=e[i].v,w=e[i].w; 32 if(dis[u]+w<dis[v]) { 33 dis[v] = dis[u] + w; 34 Q.push((node) {v, dis[v]}); 35 } 36 } 37 } 38 } 39 int main(){ 40 ios::sync_with_stdio(false); 41 cin>>n>>c>>m;int x,y; 42 for(int i=1;i<=c;i++){ 43 cin>>x;vis[x]=1; 44 } 45 for(int i=1;i<=m;i++){ 46 cin>>x>>y; 47 if(vis[y])addEdge(x,y,1); 48 else addEdge(x,y,0); 49 } 50 Dijkstra(); 51 cout<<dis[n]<<‘ ‘; 52 for(int i=0;i<=cnt;i++){ 53 e[i].w=-e[i].w; 54 } 55 vis[1]=-vis[1]; 56 Dijkstra(); 57 cout<<-dis[n]; 58 }
I:显然是矩阵快速幂。瞎搞一番一千点!之后猛然发现,,你根本不用构造矩阵,给你的就是吧。
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const ll mod = 1e9+7; 5 void exgcd(ll a,ll b,ll& d,ll& x,ll& y) { 6 if (!b) { 7 d = a; 8 x = 1; 9 y = 0; 10 } else { 11 exgcd(b, a % b, d, y, x); 12 y -= x * (a / b); 13 } 14 } 15 ll inv(ll a, ll p) { 16 ll d, x, y; 17 exgcd(a, p, d, x, y); 18 return d == 1 ? (x+p)%p : -1; 19 } 20 int n,k; 21 struct mat{ 22 ll v[105][105]; 23 mat(){ 24 memset(v,0, sizeof(v)); 25 } 26 }; 27 mat mul(mat &a,mat &b){ 28 mat c; 29 for(int i=0;i<n;i++){ 30 for(int j=0;j<n;j++){ 31 for(int k=0;k<n;k++){ 32 c.v[i][j] = (c.v[i][j]+a.v[i][k]*b.v[k][j])%mod; 33 } 34 } 35 } 36 return c; 37 } 38 mat pow(mat a, int x){ 39 mat b; 40 for(int i=0;i<n;i++) 41 b.v[i][i]=1; 42 while (x>0){ 43 if(x&1) 44 b = mul(b,a); 45 a = mul(a,a); 46 x>>=1; 47 } 48 return b; 49 } 50 int main(){ 51 scanf("%d%d",&n,&k); 52 mat a;ll tmp; 53 for(int i=0;i<n;i++){ 54 for(int j=0;j<n;j++){ 55 scanf("%lld",&tmp); 56 tmp = tmp*inv(1000000,mod)%mod; 57 a.v[i][j]=tmp; 58 } 59 } 60 mat b = pow(a,k); 61 ll ans = 0; 62 for(int i=0;i<n;i++){ 63 ans=(ans+1ll*(i+1)*b.v[0][i])%mod; 64 } 65 printf("%lld ",ans); 66 }
J:二分,然后我们找c最小的。nlognlogn竟然这么快么。。。
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 struct Node{ 5 ll a,b,c; 6 bool operator <(const Node &t)const { 7 return c>t.c; 8 } 9 }p[100005]; 10 int n;ll k; 11 bool check(ll x,ll k){ 12 priority_queue<Node> q; 13 for(int i=1;i<=n;i++){ 14 if(p[i].a<x)q.push(p[i]); 15 } 16 for(int i=1;i<=n;i++){ 17 if(p[i].a>x){ 18 ll tmp = p[i].a,all=0; 19 while (tmp>x&&!q.empty()){ 20 Node y = q.top();q.pop(); 21 if(tmp-x>=x-y.a){ 22 tmp-=(x-y.a); 23 all+=(x-y.a)*(p[i].b+y.c); 24 }else{ 25 y.a+=(tmp-x); 26 all+=(tmp-x)*(p[i].b+y.c); 27 tmp=x; 28 q.push(y); 29 } 30 } 31 k-=all; 32 if(tmp>x||k<0)return false; 33 } 34 } 35 return true; 36 } 37 int main(){ 38 ios::sync_with_stdio(false); 39 cin>>n>>k; 40 ll sum = 0,mx=0; 41 for(int i=1;i<=n;i++){ 42 cin>>p[i].a>>p[i].b>>p[i].c; 43 sum+=p[i].a;mx=max(mx,p[i].a); 44 } 45 ll l=sum/n,r=mx,ans; 46 while (l<=r){ 47 ll mid = l+r>>1; 48 if(check(mid,k)){ 49 r=mid-1; 50 ans=mid; 51 }else{ 52 l=mid+1; 53 } 54 } 55 cout<<ans<<endl; 56 } 57 /** 58 5 2 59 5 3 8 60 2 8 3 61 3 2 4 62 7 2 1 63 6 1 1 64 65 */
K:对字符串一窍不通。反正队友什么都会
以上是关于gym 101628的主要内容,如果未能解决你的问题,请参考以下文章
解决使用Monitor出现gym.error.DependencyNotInstalled: Found neither the ffmpeg nor avconv executables的问题(代码