京东校招编程题目

第一题
京东校招编程题目_第1张图片


#include <iostream>
using namespace std;
int cal(int n,int base){
    int ans=0;
    while(n)
    {
        ans+=n%base;
        n/=base;
    }
    return ans;

}
int main(int argc, const char * argv[]) {
    int n;
    cin>>n;
    int k;
    while(n--)
    {
        cin>>k;
        int ans=0;
        for(int i=1;i<=k;i++)
            if(cal(i, 2)==cal(i,10))
                ans++;
        cout<<ans<<endl;
    }
    return 0;
}

第二题
京东校招编程题目_第2张图片

#include <iostream>
#include <iomanip>
using namespace std;
double r1,x1,y1;
double r2,x2,y2;
double r3,x3,y3;
double x,y;
inline double sin2(   double r1,double x1,double y1,double x,double y)
{
    return r1*r1/((x-x1)*(x-x1)+(y-y1)*(y-y1));
}
bool check()
{
 if(sin2(r1, x1,y1,x, y)==sin2(r2, x2,y2,x, y))
     if(sin2(r1, x1,y1,x, y)==sin2(r3, x3,y3,x, y))
         return true;
    return false;
}
int main(int argc, const char * argv[]) {

    cin>>x1>>y1>>r1;
    cin>>x2>>y2>>r2;
    cin>>x3>>y3>>r3;
    if(!((r1==r2)&&(r1==r3)))
    {
        if(r1==r2)
        {
            swap(r1, r3);
            swap(x1, x3);
            swap(y1, y3);
        }
        x=((x1*r2*r2-x2*r1*r1)/(-r1*r1+r2*r2)+(x1*r3*r3-x3*r1*r1)/(-r1*r1+r3*r3))/2.0;
        y=((y1*r2*r2-y2*r1*r1)/(-r1*r1+r2*r2)+(y1*r3*r3-y3*r1*r1)/(-r1*r1+r3*r3))/2.0;
        if(!check())
        {
            cout<<"No"<<endl;
            return 0;
        }
    }else{
        double a1=2*(x2-x1);
        double b1=2*(y2-y1);
        double c1=(x1*x1-x2*x2+y1*y1-y2*y2);
        double a2=2*(x3-x1);
        double b2=2*(y3-y1);
        double c2=(x1*x1-x3*x3+y1*y1-y3*y3);
        x=(-b1*c2+b2*c1)/(a2*b1-a1*b2);
        y=(-a1*c2+a2*c1)/(a1*b2-a2*b1);
        if((a2*b1-a1*b2)==0||(a1*b2-a2*b1)==0)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<setiosflags(ios::fixed)<<x<<"\t"<<y<<endl;
    return 0;
}

你可能感兴趣的:(京东校招编程题目)