牛客小白月赛21 A,C,G,I解题记

A------Audio

思路:给你三个点求一个过这三点的圆的圆心的坐标,取两对点求每对点的中垂线方程,求其交点即可。

代码:十分简单粗暴利用两点式和斜截式即可。l1,l2分别是第一条,第二条中垂线的斜率,b1,b2分别对应两个中垂线方程斜截式中的b

#include<cstdio>
int main(void){
   
   double x[3],y[3];
    for(int i=0;i<3;i++){
   
        scanf("%lf%lf",&x[i],&y[i]);
    }
    double l1=(y[0]-y[1]);
    l1/=(x[0]-x[1]);
    l1=-1.0/l1;
    double l2=(y[1]-y[2]);
    l2/=(x[1]-x[2]);
    l2=-1.0/l2;
    double b1=(y[0]+y[1])/2-(l1*(x[0]+x[1])/2);
    double b2=(y[2]+y[1])/2-(l2*(x[2]+x[1])/2);
    double ansx=(b2-b1)/(l1-l2);
    double ansy=l1*ansx+b1;
    printf("%.3lf %.3lf",ansx,ansy);
    return 0;
} 

C------Channel

思路:给了a和b,分别求出a时刻之前能看多久,b时刻之前能看多久,然后b-a即可。

代码:

#include<cstdio>
int main(void) {
   
	long long a, b;
	while (~scanf("%lld%lld", &a, &b)) {
   
		a--;
		long long t1, t2;
		t1 = a % 60;
		t2 = b % 60;
		if (t1 > 50) {
   
			t1 = 50;
		}
		if (t2 > 50) {
   
			t2 = 50;
		}
		t1 += a / 60 * 50;
		t2 += b / 60 * 50;
		printf("%lld\n", t2 - t1);
	}
	return 0;
}

G------Game

思路:一个数字不断的拆成两个数字,对齐进行质因数分解,因为质因数不能再被分解,所以看其分解后有多少个质因数即可。要特判一下1的情况。

代码:

#include <iostream>
using namespace std;
int main(void)
{
   
	int n, n2;
	cin >> n;
	n2 = n;
	if (n == 1 ) {
   
		cout << "Nancy" << endl;
		return 0;
	}
	long long cnt = 0;
	for (int i = 2; i<= n2; i++)
	{
   
		while (n2%i == 0)
		{
   
			n2 = n2 / i;
			if (n2 != 0)
				cnt++;
		}
	}
		if (cnt & 1) {
   
			cout << "Nancy" << endl;
		}
		else {
   
			cout << "Johnson" << endl;
		}
	return 0;
}

I------I love you

狗粮题目

思路:dp,利用滚动数组优化即可,dp[i]表示第i位及之前的字串出现的子序列次数,下一个字母出现一次乘一下就好了。

	dp[8]=(dp[8]+(s[i]=='u')*dp[7])%mod;
        dp[7]=(dp[7]+(s[i]=='o')*dp[6])%mod;
        dp[6]=(dp[6]+(s[i]=='y')*dp[5])%mod;
        dp[5]=(dp[5]+(s[i]=='e')*dp[4])%mod;
        dp[4]=(dp[4]+(s[i]=='v')*dp[3])%mod;
        dp[3]=(dp[3]+(s[i]=='o')*dp[2])%mod;
        dp[2]=(dp[2]+(s[i]=='l')*dp[1])%mod;
        dp[1]=(dp[1]+(s[i]=='i'))%mod;

代码:

#include<cstdio>
#include<cstring>
#include<cctype>
using namespace std;
const long long mod=20010905;
char s[7000000];
long long dp[9];
int main(void){
   
    scanf("%s",s);
    int len=strlen(s);
    for(int i=0;i<len;i++){
   
        s[i]=tolower(s[i]);
        dp[8]=(dp[8]+(s[i]=='u')*dp[7])%mod;
        dp[7]=(dp[7]+(s[i]=='o')*dp[6])%mod;
        dp[6]=(dp[6]+(s[i]=='y')*dp[5])%mod;
        dp[5]=(dp[5]+(s[i]=='e')*dp[4])%mod;
        dp[4]=(dp[4]+(s[i]=='v')*dp[3])%mod;
        dp[3]=(dp[3]+(s[i]=='o')*dp[2])%mod;
        dp[2]=(dp[2]+(s[i]=='l')*dp[1])%mod;
        dp[1]=(dp[1]+(s[i]=='i'))%mod;
    }
    printf("%lld\n",dp[8]);
    return 0;
}

小结

​ 这场牛客的题号和题目首字母都是匹配的,出题人有心了,打了一个小时就过了六个,还是太菜了,有空补一下题吧。
如果有哪里看不懂或者有问题欢迎各在评论区指正,谢谢