contest 1.24
#include <iostream> #include<cstdio> using namespace std; int vis[60005]; int main() { int n;scanf("%d",&n); for(int i=1;i<=n-1;i++){ int t;scanf("%d",&t); vis[t]=1; } for(int i=1;i<=n;i++) if(!vis[i]) printf("%d\n",i); return 0; }
A.动态仙人掌
排序+贪心
#include <iostream> #include<cstdio> #include<algorithm> using namespace std; struct Node{double p,h;}node[300005]; bool cmp(Node a,Node b){ return a.p-a.h<b.p-b.h; } int main() { int n;scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%lf%lf",&node[i].p,&node[i].h); } sort(node+1,node+1+n,cmp); double last_rpos=node[1].p+node[1].h; double last_height=node[1].h; double last_lpos=last_rpos-2*last_height; if(last_lpos<0){ puts("-1"); return 0; } double ans=last_height; int i; for(i=2;i<=n;i++){ double l=node[i].p-node[i].h; double r=node[i].p+node[i].h; if(l>=last_rpos){ last_rpos=r; last_height=node[i].h; ans=max(ans,last_height); } else if(l>=last_lpos){ if(r<=last_rpos) continue; else{ last_rpos=r; last_height=(r-last_lpos)*1.0/2.0; ans=max(ans,last_height); } } else{ last_rpos=r; last_height=node[i].h; ans=max(ans,last_height); } last_lpos=last_rpos-2*last_height; if(last_lpos<0) break; } if(i<=n) puts("-1"); else printf("%.1f\n",ans); return 0; }
E.旅程
倒过来操作
#include <iostream> #include<cstdio> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; struct Query{ ll op,u,v,w; }q[100005]; ll Map[205][205]; ll ans[100005]; int main() { ll n,m;scanf("%lld%lld",&n,&m); for(ll i=1;i<=n;++i){ for(ll j=1;j<=n;++j){ scanf("%lld",&Map[i][j]); } } for(ll i=1;i<=m;i++){ ll op,u,v; scanf("%lld%lld%lld",&op,&u,&v); q[i].op=op,q[i].u=u,q[i].v=v; if(op==1){ q[i].w=Map[u][v]; Map[u][v]=inf; } } for(ll k=1;k<=n;k++){ for(ll i=1;i<=n;i++){ for(ll j=1;j<=n;j++){ Map[i][j]=min(Map[i][j],Map[i][k]+Map[k][j]); } } } ll cnt=0; for(ll i=m;i>=1;i--){ ll op=q[i].op,u=q[i].u,v=q[i].v; if(op==2){ ans[++cnt]=Map[u][v]; } else{ Map[u][v]=min(Map[u][v],q[i].w); for(ll i=1;i<=n;i++){ for(ll j=1;j<=n;j++){ Map[i][j]=min(Map[i][j],Map[i][u]+Map[u][j]); } } for(ll i=1;i<=n;i++){ for(ll j=1;j<=n;j++){ Map[i][j]=min(Map[i][j],Map[i][v]+Map[v][j]); } } } } for(ll i=cnt;i>=1;i--){ if(ans[i]==inf) puts("-1"); else printf("%lld\n",ans[i]); } return 0; }
D.妹子
几何
#include <iostream> #include<cstdio> #include<cmath> using namespace std; int a1,b1,a2,b2; bool check1(){ if(a2>a1) return 0; double angle1=asin(a1*1.0/sqrt(a2*a2+b2*b2)); double angle2=atan(a2*1.0/(b2*1.0)); return b2*cos(angle1-angle2)+a2*sin(angle1-angle2)<=b1; } bool check2(){ if(a1>a2) return 0; double angle1=asin(a2*1.0/sqrt(a1*a1+b1*b1)); double angle2=atan(a1*1.0/(b1*1.0)); return b1*cos(angle1-angle2)+a1*sin(angle1-angle2)<=b2; } int main() { int n;scanf("%d",&n); while(n--){ scanf("%d%d",&a1,&b1); if(a1>b1) swap(a1,b1); scanf("%d%d",&a2,&b2); if(a2>b2) swap(a2,b2); if((a1<=a2&&b1<=b2)||(a2<=a1&&b2<=b1)) printf("Yes\n"); else{ if(check1()||check2()) printf("Yes\n"); else printf("No\n"); } } return 0; }
转载请注明出处:https://www.cnblogs.com/lllxq/