CCPC-Wannafly Winter Camp Day2 Div2

Erase Numbers II
题解:Div2数据量较小,最简单的是直接枚举两个数字,然后直接比较得出最大数字是多少,我们队采用的方法是从后往前找出当前数字后面最大的数字,和这个数字组合出来的最大的数字[需要注意的是得开unsigned long long才存的下]

#include<bits/stdc++.h>
const int N = 6005;
using namespace std;
unsigned long long max(unsigned long long x,unsigned long long y){
    return x>y?x:y;
}
int T;
unsigned long long arr[N];
priority_queue<unsigned long long>q; 
char ch1[110],ch2[110];
int n;
unsigned long long ans = 0;
int main(){
    scanf("%d",&T);
    unsigned long long k = 1;
    for(int t=1;t<=T;++t){
        memset(ch1,0,sizeof(ch1));
        memset(ch2,0,sizeof(ch2));
        ans = 0;
        scanf("%d",&n);
        while(!q.empty())q.pop();
        for(int i=1;i<=n;++i){
            scanf("%lld",&arr[i]);
        }
        q.push(arr[n]);
        for(int i=n-1;i>=1;--i){
            unsigned long long temp1 = arr[i];
            unsigned long long temp2 = q.top();
            q.push(temp1);
            sprintf(ch1,"%llu",temp1);
            sprintf(ch2,"%llu",temp2);

            strcat(ch1,ch2);

            sscanf(ch1,"%llu",&temp1);

            ans = max(ans,temp1); 
        }
            printf("Case #%d: %llu\n",t,ans);
    }
    
    return 0;
}

Cosmic Cleaner

推导一个圆缺口公式然后用计算几何板子就没问题了

#include <bits/stdc++.h>
using namespace std;

const double PI = acos(-1.0);

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;
void SphereInterVS(sphere a, sphere b,double &v/*,double &s*/) {
    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.0 * acos((a.r*a.r + d*d - b.r*b.r) / (2.0 * a.r*d));  //余弦公式计算r1对应圆心角,弧度
    double angle_b = 2.0 * 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圆所对应的球缺部分体积
     v = v1 + v2;//相交部分体积
    //double s1 = PI*a.r*x1;  //r1对应球冠表面积
    //double s2 = PI*a.r*x2;  //r2对应球冠表面积
    // s = 4 * PI*(a.r*a.r + b.r*b.r) - s1 - s2;//剩余部分表面积
}

int x[111],y[111],z[111],r[111];

int main()
{
    int T;
    scanf("%d",&T);
    int t=0;
    while(t++<T)
    {
        int n;
        scanf("%d",&n);

        int xxx,yyy,zzz,rrr;
        for(int i=0;i<n;i++)
            scanf("%d %d %d %d",&x[i],&y[i],&z[i],&r[i]);
        
        scanf("%d %d %d %d",&xxx,&yyy,&zzz,&rrr);
        
        sphere cen;
        cen.centre.x=xxx;
        cen.centre.y=yyy;
        cen.centre.z=zzz;
        cen.r=rrr;
        
        double sumv=0;
        for(int i=0;i<n;i++)
        {
            double v;
            sphere aa;
            aa.centre.x=x[i];
            aa.centre.y=y[i];
            aa.centre.z=z[i];
            aa.r=r[i];
            double d=dist(aa.centre,cen.centre);
            
            if(cen.r>d+aa.r)
                v=4.0*PI*aa.r*aa.r*aa.r/3.0;
            else if(cen.r+aa.r<d)
                v=0.;
            else
            {
                double h1=cen.r-(cen.r*cen.r-aa.r*aa.r+d*d)/(2.*d);
                double v1=PI*(3.*cen.r-h1)*h1*h1/3.0;
                double h2=aa.r-(aa.r*aa.r-cen.r*cen.r+d*d)/(2.*d);
                double v2=PI*(3.*aa.r-h2)*h2*h2/3.0;
                v=v1+v2;
            }
            sumv+=v;
        }
        printf("Case #%d: %.10lf\n",t,sumv);
    }
    
    return 0;
}
Last modification:January 28th, 2019 at 07:59 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment