CCPC-Wannafly Winter Camp Day2 (Div2)
目录
A Erase Numbers II
【题目】
【解题思路】
题意就是在n个数中找到两个数组合起来得到最大值,n很小,直接暴力模拟即可。
【代码】
#include<bits/stdc++.h>
using namespace std;
const int maxn=6005;
typedef unsigned long long ull;
int a[maxn];
ull add(ull a,ull b)
{
ull t=b;
while(t)
{
a*=10;
t/=10;
}
return a+b;
}
int main()
{
int T,n,kase=1;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
ull ans=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
ans=max(ans,add(a[i],a[j]));
}
}
printf("Case #%d: %llu\n",kase++,ans);
}
}
B Erase Numbers I
【题目】
【解题思路】
这题留个坑...虽然比赛的时候A了 但事后发现有点问题 可能比赛的数据比较水
【代码】
H Cosmic Cleaner
【题目】
【解题思路】
就是求球与球之间相交的体积,套个模板就行了。
求相交体积https://blog.****.net/enterprise_/article/details/81624174
【代码】
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
typedef long long LL;
const double PI = acos(-1.0);
const int maxn=1000;
//板子
typedef struct point
{
double x,y,z;
point() {}
point(double a, double b,double c) {
x = a;
y = b;
z = c;
}
point operator -(const point &b)const { //返回减去后的新点
return point(x - b.x, y - b.y,z-b.z);
}
point operator +(const point &b)const { //返回加上后的新点
return point(x + b.x, y + b.y,z+b.z);
}
//数乘计算
point operator *(const double &k)const { //返回相乘后的新点
return point(x * k, y * k,z*k);
}
point operator /(const double &k)const { //返回相除后的新点
return point(x / k, y / k,z/k);
}
double operator *(const point &b)const { //点乘
return x*b.x + y*b.y+z*b.z;
}
}point;
double dist(point p1, point p2) { //返回平面上两点距离
return sqrt((p1 - p2)*(p1 - p2));
}
typedef struct sphere {//球
double r;
point centre;
}sphere;
double SphereInterVS(sphere a, sphere b) {
double d = dist(a.centre, b.centre);//球心距
double t = (d*d + a.r*a.r - b.r*b.r) / (2.0 * d);//
double h = sqrt((a.r*a.r) - (t*t)) * 2;//h1=h2,球冠的高
double angle_a = 2 * acos((a.r*a.r + d*d - b.r*b.r) / (2.0 * a.r*d)); //余弦公式计算r1对应圆心角,弧度
double angle_b = 2 * acos((b.r*b.r + d*d - a.r*a.r) / (2.0 * b.r*d)); //余弦公式计算r2对应圆心角,弧度
double l1 = ((a.r*a.r - b.r*b.r) / d + d) / 2;
double l2 = d - l1;
double x1 = a.r - l1, x2 = b.r - l2;//分别为两个球缺的高度
double v1 = PI*x1*x1*(a.r - x1 / 3);//相交部分r1圆所对应的球缺部分体积
double v2 = PI*x2*x2*(b.r - x2 / 3);//相交部分r2圆所对应的球缺部分体积
double v = v1 + v2;//相交部分体积
return v;
}
//
sphere roll[maxn],clean;
int main()
{
int cnt=1;
int t;scanf("%d",&t);
while(t--)
{
int n;scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%lf%lf%lf%lf",&roll[i].centre.x,&roll[i].centre.y,&roll[i].centre.z,&roll[i].r);
}
scanf("%lf%lf%lf%lf",&clean.centre.x,&clean.centre.y,&clean.centre.z,&clean.r);
double v=0;
//相离;
for(int i=0;i<n;i++)
{
if(dist(roll[i].centre,clean.centre)>=(roll[i].r+clean.r))continue;
else if(dist(roll[i].centre,clean.centre)+roll[i].r<=clean.r)
{
v+=(4.0/3.0)*PI*roll[i].r*roll[i].r*roll[i].r;
}
else{
v+=SphereInterVS(roll[i], clean);
}
}
printf("Case #%d: %.20lf\n",cnt++,v);
}
}