牛客小白月赛21(回顾补题)

A Audio

求取三角形的外心,使用公式即可。

#include<bits/stdc++.h>
using namespace std;
///精度误差,返回值小于等与10^-8即可 
struct Point
{
	double x,y;
};
struct Point T[5];
Point waixin(Point a,Point b,Point c)
{
    double a1=b.x-a.x,b1=b.y-a.y,c1=(a1*a1+b1*b1)/2;
    double a2=c.x-a.x,b2=c.y-a.y,c2=(a2*a2+b2*b2)/2;
    double d=a1*b2-a2*b1;
    struct Point z;
    z.x=a.x+(c1*b2-c2*b1)/d;
    z.y=a.y+(a1*c2-a2*c1)/d;
    return z;
}
Point zhongxin(Point a,Point b,Point c)
{
	struct Point orth1;
    orth1.x=(a.x+b.x+c.x)/3;
    orth1.y=(a.y+b.y+c.y)/3;
	return orth1;	
} 
Point neixin(Point a,Point b,Point c)
{
	double dista=sqrt((b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y));
    double distb=sqrt((c.x-a.x)*(c.x-a.x)+(c.y-a.y)*(c.y-a.y));
    double distc=sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
    struct Point incen;
    incen.x=(dista*a.x+distb*b.x+distc*c.x)/(dista+distb+distc);
    incen.y=(dista*a.y+distb*b.y+distc*c.y)/(dista+distb+distc);
    return incen;
}
Point zhixin(Point a,Point b,Point c)
{
	double dista=sqrt((b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y));
    double distb=sqrt((c.x-a.x)*(c.x-a.x)+(c.y-a.y)*(c.y-a.y));
    double distc=sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
    double sum1=(c.x-a.x)*(c.x*(b.x-a.x)+c.y*(b.y-a.y))/(b.x-a.x);
    double sum2=(b.y-a.y)*(c.x-a.x)/(b.x-a.x);
    struct Point orth2;
    orth2.y=(b.x*(c.x-a.x)+b.y*(c.y-a.y)-sum1)/((c.y-a.y)-sum2);
    orth2.x=(c.x*(b.x-a.x)+c.y*(b.y-a.y)-(b.y-a.y)*orth2.y)/(b.x-a.x);
    return orth2;
}
int main() {
	Point a,b,c;
	cin>>a.x>>a.y;
	cin>>b.x>>b.y;
	cin>>c.x>>c.y;
	Point temp=waixin(a,b,c);
	printf("%.3lf %.3lf\n",temp.x,temp.y);
	return 0;
}

C Channels

区间取模问题,注意当余数大于等于50的情况即可

#include<bits/stdc++.h>
using namespace std;
int main() {
    long long t1,t2;
    while(cin>>t1>>t2) {
        t1--,t2--;
        long long sum1=t1/60,sum2=t1%60;
        long long sum3=t2/60,sum4=t2%60;
        long long ans=0;
        if(sum2>=50)
        	sum1++,sum2=0;
		if(sum4>=50)
			sum4=49;
		ans=(sum3-sum1)*50+sum4-sum2+1;
    	cout<<ans<<endl;
    }
    return 0;
}

D DDoS

拓扑排序求路径数

#include<bits/stdc++.h>
using namespace std;
const int p=20010905;
struct edge {
    int v,h;
} e[200005];
int h[100005],r[100005],n,m,tot;
int q[100005],head,tail,f[100005];
inline int rd() {
    char ch=getchar();
    int x=0;
    while(ch<'0' || ch>'9') ch=getchar();
    while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x;
}
inline void add(int u,int v) {
    e[++tot]=(edge) {
        v,h[u]
    },h[u]=tot;
}
int main() {
    scanf("%d%d",&n,&m);
    for(int u,v,z;m;m--)
        u=rd(),v=rd(),z=rd(),r[v]++,add(u,v);
    f[1]=q[tail=1]=1;
    while(head<tail){
        int u=q[++head];
        for (int i=h[u],v;i;i=e[i].h){
            v=e[i].v,r[v]--;
            if(!r[v]) 
                q[++tail]=v;
            f[v]=(f[v]+f[u])%p;
        }
    }
    printf("%d",f[n]);
}

E Exams

简单排序,注意精度

#include<bits/stdc++.h>
using namespace std;
struct node{
    double xuefen;
    int zongfen;
};
vector<node> p;
int main() {
    int n;
    cin>>n;
    double sumxuefen=0.0;
    for(int i=0;i<n;i++) {
        int t;
        double z,a,a1,b,b1,c,c1;
        cin>>t>>z>>a>>a1>>b>>b1>>c>>c1;
        if(t==0||t==1) {
            double sum=a*a1+b*b1+c*c1;
            int sum1=(sum*10+5)/10;
            node temp;
            temp.xuefen=z;
            temp.zongfen=sum1;
            p.push_back(temp);
            sumxuefen+=z;
        } else
            continue;
    }
    double ans=0.0;
	for(int i=0;i<p.size();i++)
        ans=ans+p[i].zongfen*(p[i].xuefen/sumxuefen);
    //cout<<ans<<endl;
    int zhengshu=ans*1000;
    int yushu=zhengshu%10;
    if(yushu<=4) {
    	printf("%.2lf\n",ans);
	} else {
		printf("%.2lf\n",(ans*1000+5)/1000);
	}
	return 0;
}

F Fool Problem

找规律,奇偶性

#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    int len1=s.length()-1;
    if((s[len1]-'0')%2==0)
        cout<<1<<endl;
    else
        cout<<-1<<endl;
    return 0;
}

G Game

唯一分解定理,质因数的个数

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n;
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
//    freopen(".in","r",stdin);
//    freopen(".out","w",stdout);
    int i,j,c=0;
    cin>>n;
    while(n!=1)
    {
        for(i=2; i<=n; i++)
        {
            if(n%i==0)
            {
                n=n/i;
                c++;
                break;
            }
        }
    }
    if(c%2==0)
        cout<<"Johnson";
    else
        cout<<"Nancy";
 
    return 0;
}

H ”Happy New Year!“

注意输出时同时输出分号

#include<bits/stdc++.h>
using namespace std;
int main() {
    cout<<"”Happy New Year!“";
    return 0;
}

I I love you

简单DP,每当存在一个符合字符就说明转移到了下一个过程

#include<bits/stdc++.h>
using namespace std;
char c,str[8]= {'i','l','o','v','e','y','o','u'};
const int MOD=20010905;
int f[8];
int main() {
    f[0]=1;
    while(~scanf("%c",&c)) {//到读不到字符为止
        for(int i=0;i<8;i++) {
            if(c==str[i] || c==str[i]-32)//小写或大写都行
                f[i+1]=(f[i+1]+f[i])%MOD;
        }
    }
    printf("%d",f[8]);//iloveyou的数目
}

J Jelly

三维BFS

#include<bits/stdc++.h>
using namespace std;
const int MAXN=111;
struct node{
    int x,y,z;
    int sum=0;
};
queue<node> p;
char s[MAXN][MAXN][MAXN];
bool vis[MAXN][MAXN][MAXN];
int next1[6][3]={{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};
int main() {
    int n;
    cin>>n;
    getchar();
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++)
            cin>>s[i][j];
        getchar();
    }
    node temp;
    temp.x=0,temp.y=0,temp.z=0,temp.sum=1;
    p.push(temp);
    vis[0][0][0]=true;
    int ans=0;
    bool flag=false;
    while(!p.empty()) {
        node k=p.front();
        p.pop();
        if(k.x==(n-1)&&k.y==(n-1)&&k.z==(n-1)) {
            flag=true;
            ans=k.sum;
            break;
        } else {
            for(int i=0;i<6;i++) {
                int x1=k.x+next1[i][0];
                int y1=k.y+next1[i][1];
                int z1=k.z+next1[i][2];
                if(x1<0||x1>=n||y1<0||y1>=n||z1<0||z1>=n)
                    continue;
                else {
                    if(vis[x1][y1][z1]||s[x1][y1][z1]=='*')
                        continue;
                    else {
                        node k1;
                        k1.x=x1,k1.y=y1,k1.z=z1,k1.sum=k.sum+1;
                        vis[x1][y1][z1]=true;
                        p.push(k1);
                    }
                }
            }
        }
    }
    if(flag)
        cout<<ans<<endl;
    else
        cout<<"-1\n";
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值