站军姿
2bc*cosA=b^2+c^2-a^2
#include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> const double pi=3.14159265358979323846264; using namespace std; void work() { int x1,y1,r1,x2,y2,r2; scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2); double d=sqrt(abs(x1-x2)*abs(x1-x2)+abs(y1-y2)*abs(y1-y2)); if(r1+r2<=d)//相离 { double ans=r1*r1*pi+r2*r2*pi; printf("%.3lf\n",ans); return; } if(r1+r2>d&&abs(r1-r2)>=d)//内含 { double ans=max(r2,r1)*max(r2,r1)*pi; printf("%.3lf\n",ans); return; } //相交 double ans=r1*r1*pi+r2*r2*pi; double j1=acos((d*d+r1*r1-r2*r2)/(2*d*r1)); double j2=acos((d*d+r2*r2-r1*r1)/(2*d*r2)); ans-=(r1*r1*j1+r2*r2*j2); ans+=d*r1*sin(j1); printf("%.3lf\n",ans); } int main() { //freopen("jh.in","r",stdin); freopen("standing.in","r",stdin); freopen("standing.out","w",stdout); int T;scanf("%d",&T); while(T--) { work(); } return 0; }
对刚
3
#include<iostream> #include<cstdio> #include<cstring> #define maxn 100010 using namespace std; int n,t,sum; bool vis[maxn]; struct node{ int nxt,pre; }q[maxn]; int main(){ //freopen("Cola.txt","r",stdin); freopen("resist.in","r",stdin); freopen("resist.out","w",stdout); scanf("%d%d",&n,&t); sum=n-1; for(int i=1;i<=n;i++){ q[i].pre=i-1;q[i].nxt=i+1; } q[1].pre=n;q[n].nxt=1; int pos=1,cnt=0; while(sum){ cnt++; if(cnt==t){ q[q[pos].pre].nxt=q[pos].nxt; q[q[pos].nxt].pre=q[pos].pre; vis[pos]=1; sum--; cnt=0; } pos=q[pos].nxt; } for(int i=1;i<=n;i++){ if(!vis[i]){ printf("%d",i); return 0; } } }
隔壁
#include<iostream> #include<cstdio> #include<cstring> using namespace std; #define maxn 1010 int n,m,a[maxn],b[maxn],c[maxn]; long long map[maxn][maxn]; long long ans1,ans2; bool v1[maxn]; int main(){ //freopen("Cola.txt","r",stdin); freopen("neighbor.in","r",stdin); freopen("neighbor.out","w",stdout); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)scanf("%d",&c[i]); for(int i=1;i<=m;i++)scanf("%d",&b[i]); for(int i=1,j=n;i<=n;i++,j--)a[i]=c[j]; int mark; for(int i=1;i<=n;i++){ bool flag=0; for(int j=1;j<=m;j++){ if(b[j]==a[i]&&!v1[j]){ v1[j]=1; ans1+=a[i]; flag=1; break; } if(b[j]>a[i])mark=j; } if(!flag){ ans1+=a[i]; } } for(int i=1;i<=m;i++){ if(!v1[i]){ ans1+=b[i]; } } cout<<ans1<<' '; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(b[j]>=a[i]) map[i][j]=a[i]; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(b[j]<=a[i]) map[i][j]=b[j]; ans2+=map[i][j]; } } cout<<ans2; return 0; }