新生选拔赛暂存

本文解析了多个C++编程竞赛题目,包括判断奇偶、数组操作、几何计算等,通过示例代码详细展示了如何使用C++标准库解决实际问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//a
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int T;
	//freopen("input.txt","r",stdin);
	scanf("%d",&T);
	for(int t=1;t<=T;t++)
	{
		ll n,k;
		scanf("%lld%lld",&n,&k);
		ll temp=n-3;
		if(temp%2==0) printf("BH\n");
		else printf("LYF\n");
	}
	return 0;
}



//c
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100000+10];
int main()
{
	//freopen("input.txt","r",stdin);
	int T;
	scanf("%d",&T);
	for(int t=1;t<=T;t++)
	{
		int n;
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		sort(a+0,a+n);
		printf("%d\n",a[n-1]-a[0]);
	}
	return 0;
}

 

//f
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define esp 1e-8

using namespace std;
const double pi= 3.1415926535898;

struct Circle{
    double x,y;
    double r;
};

double calArea(Circle c1, Circle c2)
{
    double d;
    double s,s1,s2,s3,angle1,angle2,temp;

    d=sqrt((c1.x-c2.x)*(c1.x-c2.x)+(c1.y-c2.y)*(c1.y-c2.y));
    if(d>=(c1.r+c2.r))
        return 0;
    if((c1.r-c2.r)>=d)
        return acos(-1.0)*c2.r*c2.r;
    if((c2.r-c1.r)>=d)
        return acos(-1.0)*c1.r*c1.r;

    angle1=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
    angle2=acos((c2.r*c2.r+d*d-c1.r*c1.r)/(2*c2.r*d));

    s1=angle1*c1.r*c1.r;s2=angle2*c2.r*c2.r;
    s3=c1.r*d*sin(angle1);
    s=s1+s2-s3;

    return s;
}

int main()
{
	//freopen("input.txt","r",stdin);
	int T;
	scanf("%d",&T);
	for(int t=1;t<=T;t++)
	{
		Circle c1,c2;
		int x1,y1,x2,y2,r1;
		scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&r1);
		c1.x=x1;
		c1.y=y1;
		c2.x=x2;
		c2.y=y2;
		c1.r=r1;
		double sat=0,end=1e5,mid=(sat+end)/2.0,tar=pi*r1*r1/2,r2,temps;
		c2.r=mid;
		temps=calArea(c1,c2);
		while(abs(temps-tar)>esp)
		{
			if(temps-tar<0) sat=mid;
			else end=mid;
			mid=(sat+end)/2.0;
			c2.r=mid;
			temps=calArea(c1,c2);
		}
		printf("%.4f\n",mid);
	}
	return 0;
}





 

//G
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
	//freopen("input.txt","r",stdin);
	int T;
	scanf("%d",&T);
	for(int t=1;t<=T;t++)
	{
		int a[1000+10];
		memset(a,0,sizeof(a));
		int n;
		scanf("%d",&n);
		//cout<<n<<endl;
		for(int i=1;i<=n;i++)
		{
			int temp;
			scanf("%d",&temp);
			a[temp]++;
		}
		
		int maximum=-1;
		for(int i=1;i<=1000;i++)
		{
			maximum=max(maximum,a[i]);
		}
		for(int i=1;i<=1000;i++)
		{
			if(a[i]==maximum) printf("%d ",i);
		}
		printf("\n");
	}
	return 0;
}


 

//h
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
const ll f[]={1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170,1836311903,2971215073,4807526976,7778742049,12586269025,20365011074,32951280099,53316291173,86267571272,139583862445,225851433717,365435296162,591286729879,956722026041,1548008755920,2504730781961,4052739537881,6557470319842,10610209857723,17167680177565,27777890035288,44945570212853,72723460248141,117669030460994,190392490709135,308061521170129,498454011879264,806515533049393,1304969544928657,2111485077978050,3416454622906707,5527939700884757,8944394323791464,14472334024676221,23416728348467685,37889062373143906,61305790721611591,99194853094755497,160500643816367088,259695496911122585,420196140727489673,679891637638612258,1100087778366101931,1779979416004714189,2880067194370816120,4660046610375530309,7540113804746346429,12200160415121876738,19740274219868223167,31940434634990099905,51680708854858323072,83621143489848422977,135301852344706746049};
int main()
{
	//freopen("input.txt","r",stdin);
	int T;
	scanf("%d",&T);
	for(int t=1;t<=T;t++)
	{
		int n;
		ll m;
		scanf("%d%lld",&n,&m);
		while(n!=0&&n!=1)
		{
			//cout<<m<<","<<n<<endl;
			if(m<=f[n-1])
			{
				n=n-1;
			}
			else 
			{
				m=m-f[n-1];
				n=n-2;
			}
		}
		if(n==0) printf("b\n");
		else printf("a\n");
	}
	return 0;
}


 

//i
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100000];
int main()
{
	//freopen("input.txt","r",stdin);
	int T;
	scanf("%d",&T);
	for(int t=1;t<=T;t++)
	{
		int n,k;
		scanf("%d%d",&n,&k);
		for(int i=1;i<=n;i++)
		{
			char temp;
			//scanf("%c",&temp);
			cin>>temp;
			//cout<<temp;
			if(temp=='a') a[i]=1;
			else if(temp=='b') a[i]=2;
			else if (temp=='c') a[i]=3;
			//cout<<a[i];
		}
		int counter=0;
		int temp=0;
		for(int i=1;i<=n;i++)
		{
			if(a[i]==1)
			{
				counter++;
				temp++;
			}
			else if(a[i]==2)
			{
				if(i-1>=1&&a[i-1]==1)
				{
					counter+=2;
					temp=1;
				}
				else 
				{
					counter++;
					temp++;
				}
			}
			else
			{
				if(temp>=k)
				{
					counter+=2;
					temp=1;
				}
				else
				{
					counter++;
					temp++;
				}
			}
			//cout<<a[i]<<","<<counter<<","<<temp<<endl;
		}
		printf("%d\n",counter);
	}
	return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值