“蔚来杯“2022牛客暑期多校训练营5 待续

顺序:KCBFH

K.headphone

题意:给定n,k,表示n对耳机,和B已经拿了k对耳机,问A至少要拿几个耳机,才能保证A拿到的对数比B多
解:鸽巢原理
代码

#include<bits/stdc++.h>
using namespace std;
int n,k;
int main()
 {
    ios::sync_with_stdio(false);
	cin.tie(0);
	int t; 
 	while(cin>>n>>k)
 	{
 		t=n-k;
 		if(t>k)
 		{
 			cout<<t+k+1;
		 }
		else
		  cout<<-1;
		cout<<endl;
	 }
  } 

C.Bit Transmission

题意&题解:

请添加图片描述


代码:

#include<bits/stdc++.h>
using namespace std;
int n,tn;
const int N=1e5+11;
int cnt1[N],cnt2[N];
int k;
string s;
int x;
bool flag;
void print(int x[])
{
	for(int i=1;i<=n;i++)
	  cout<<x[i]<<" ";
	cout<<endl;
}
int main()
 {
    cin>>n;
    tn=n*3;
    flag=1;
    while(tn--)
    {
    	cin>>k>>s;
    	if(s=="YES")
    	  cnt1[k+1]++;
    	else 
    	  cnt2[k+1]++;
	}
//	print(cnt1);
//	print(cnt2);
	for(int i=1;i<=n;i++)
	{
		if((cnt1[i]>1 && cnt2[i]>1 )|| (cnt1[i]==cnt2[i]) ||( cnt1[i]==0 && cnt2[i]==0))
		{
			flag=0;
		
		}
		if(cnt1[i] && cnt2[i])
		{
			x++;
		}
	}
	if(x>1)
	  flag=0;
	if(x==0)
	{
		for(int i=1;i<=n;i++)
		{
			if(cnt1[i]+cnt2[i]==1)
			  flag=0;
		}
	}
	
	if(flag)
	{
		for(int i=1;i<=n;i++)
		{
			if(cnt1[i] && cnt2[i]==0)
			  cout<<1;
			else if(cnt1[i]==0)
			  cout<<0;
			else 
			{
				if(cnt1[i]==1)
				  cout<<0;
				else
				  cout<<1;
			}
		}
	 } 
	else
	  cout<<-1;
	return 0;
  } 

B Watches

题意:第一行给定n,m,分别表示n块手表和拥有的钱,第二行,给定n个数a[i],表示每块手表的价格。另外,每块手表会额外花费 i*k的价格,k表示一共买了几块。
解: 二分+排序
代码

#include<bits/stdc++.h>
using namespace std;
int n,m;
const int N=1e5+11;
int a[N];
typedef long long ll;
ll w[N];
bool pd(int k)
{
	for(int i=1;i<=n;i++)
	  w[i]=1ll*a[i]+k*i;
	sort(w+1,w+1+n);
	ll sum=0;
	for(int i=1;i<=k;i++)
	{
		sum+=w[i];
	}
	if(sum<=m)
	  return 1;
	return 0;
}
void solve()
{
	int l=0,r=N;
	int ans=(l+r)>>1;
	int mid;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(pd(mid))
		{
			l=mid+1;
			ans=mid;
		}
		else 
		  r=mid-1;
	}
	cout<<ans;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	  cin>>a[i];
	solve();
	return 0;
}

F.A Stack of CDs

题意:给定多个圆,覆盖之后,其投影的周长
官方题解:
请添加图片描述
代码:

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

const int maxn = 10005;
const double pi = 3.1415926535897932;
const double pi2 = 2*pi;

struct Point
{
	double x, y;
};

inline double sqr(double x)
{
	return x*x;
}

inline double get_dist(Point x, Point y)
{
	return sqrt(sqr(x.x-y.x) + sqr(x.y-y.y));
}

struct Circle
{
	Point O;
	double r;
} c[maxn];

inline double get_dist(Circle x, Circle y)
{
	return get_dist(x.O, y.O);
}

int n;

struct Fugai
{
	double l, r;

	inline bool operator < (const Fugai& other) const
	{
		return l < other.l;
	}
} fugai[maxn];

int nown;
inline void cha(double l, double r)
{
	fugai[++nown] = (Fugai)
	{
		l, r
	};
}

bool gaif = false;//gaif = true表示该圆盘被上面的大圆盘完全覆盖

inline void jiao(Circle A, Circle B)
{
	double dist = get_dist(A, B);
	if(dist > A.r+B.r || A.r + dist < B.r)//没有任何覆盖
		return;
	if(dist + B.r < A.r)//如果被一个大圆盘完全覆盖,直接跳出
	{
		gaif = true;
		return;
	}
	double alpha = acos((sqr(B.r)+sqr(dist)-sqr(A.r))/(B.r*dist*2.));//上图中的角CAD
	double beta = atan2(B.O.y-A.O.y, A.O.x-B.O.x);//上图中的角CAE
	double jiao1 = beta-alpha;//线段覆盖中的l
	double jiao2 = beta+alpha;//线段覆盖中的r
	if(jiao1 < 0 && jiao2 < 0)//对极角的一些特判
	{
		jiao1 += pi2, jiao2 += pi2;
	}
	if(jiao1 >= 0 && jiao2 <= pi2)
		cha(jiao1, jiao2);
	else
	{
		if(jiao1 < 0)
		{
			cha(jiao1+pi2, pi2);
			cha(0, jiao2);
		}
		else
		{
			cha(jiao1, pi2);
			cha(0, jiao2-pi2);
		}
	}
}

inline double get_ans()
{
	double ans = 0;
	sort(fugai+1, fugai+nown+1);
	double lastr = fugai[1].l;
	for(int i = 1; i <= nown; ++i)
	{
		if(lastr >= fugai[i].r)
			continue;
		if(fugai[i].l > lastr)
			ans += fugai[i].r - fugai[i].l;
		else
			ans += fugai[i].r - lastr;
		lastr = fugai[i].r;
	}
	return ans;
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%lf%lf%lf", &c[i].O.x, &c[i].O.y,&c[i].r);
	double ans = 0;
	for(int i = n; i; --i)
	{
		nown = 0;
		for(int j = n; j > i; --j)
		{
			jiao(c[j], c[i]);
			if(gaif)
				break;
		}
		if(gaif)
			gaif = false;
		else
			ans += (pi2-get_ans())*c[i].r;
		nown = 0;
	}
	printf("%.7f", ans);
	return 0;
}

H Cutting Paper

请添加图片描述
好像题解是错的,其实是
求这些部分的面积:
请添加图片描述
代码

#include<bits/stdc++.h>
using namespace std;
int n;
const double pi=3.14159265358979;
int main()
{
	cin>>n;
	printf("%.8lf",(n*1.0/2)*(n*1.0/2)*2+pi*(n*1.0/2)*(n*1.0/2)/2);
	
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dai _ tu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值