AcWing109

AcWing 109

5041. 函数 - AcWing题库

#include<bits/stdc++.h> 
using namespace std;
typedef long long LL;
const int INF = 1e5 + 10;
const int MOD = 1e9 + 7;


int main()
{
	int n;
	cin>>n;
	if(n & 1)
	{
		cout<<0<<endl;
	}
	else 
	{
		int num = n / 2;
		int ans = pow(2 , num);
		cout<<ans<<endl;
	}
	return 0;
	
}


5042. 病毒 - AcWing题库

//BFS
#include<bits/stdc++.h> 
using namespace std;
typedef long long LL;
const int INF = 2e3 + 10;
const int MOD = 1e9 + 7;
int n,m,k,ans = 0;
bool vis[INF][INF];
typedef struct{
	int xi;
	int yi;
}SE;
queue<SE>q;

int main()
{
	cin>>n>>m;
	cin>>k;
	memset(vis,0,sizeof(vis));
	SE s1;
	for(int i = 1;i <= k;i ++)
	{
		int xi,yi;
		cin>>xi>>yi;
		s1.xi = xi;
		s1.yi = yi;
		q.push(s1);
		vis[xi][yi] = 1;
		ans++;
	}
	if(m * n == k)
	{
		cout<<s1.xi<<" "<<s1.yi<<endl;
	}
	else
//	cout<<ans<<endl;
	while(!q.empty())
	{
		SE s1 = q.front();
		q.pop();
//		cout<<s1.xi<<" "<<s1.yi<<endl;
		if(s1.xi - 1 >= 1 && !vis[s1.xi - 1][s1.yi])
		{
			SE s2;
			s2.xi = s1.xi - 1;
			s2.yi = s1.yi;
			q.push(s2);
			vis[s2.xi][s2.yi] = 1;
			ans ++;
			if(ans == n * m)
			{
//				cout<<ans<<endl;
				cout<<s2.xi<<" "<<s2.yi<<endl;
				break;
			}
		}//上 
		if(s1.yi - 1 >= 1&&!vis[s1.xi][s1.yi - 1])
		{
			SE s2;
			s2.xi = s1.xi;
			s2.yi = s1.yi - 1;
			q.push(s2);
			vis[s2.xi][s2.yi] = 1;
			ans ++;
			if(ans == n * m)
			{
//				cout<<ans<<endl;
				cout<<s2.xi<<" "<<s2.yi<<endl;
				break;
			}
		}//左 
		if(s1.xi + 1 <= n && !vis[s1.xi + 1][s1.yi])
		{
			SE s2;
			s2.xi = s1.xi + 1;
			s2.yi = s1.yi;
			q.push(s2);
			vis[s2.xi][s2.yi] = 1;
			ans ++;
			if(ans == n * m)
			{
//				cout<<ans<<endl;
				cout<<s2.xi<<" "<<s2.yi<<endl;
				break;
			}
		}//下 
		if(s1.yi + 1 <= m&&!vis[s1.xi][s1.yi + 1])
		{
			SE s2;
			s2.xi = s1.xi;
			s2.yi = s1.yi + 1;
			q.push(s2);
			vis[s2.xi][s2.yi] = 1;
			ans ++;
			if(ans == n * m)
			{
//				cout<<ans<<endl;
				cout<<s2.xi<<" "<<s2.yi<<endl;
				break;
			}
		}//右 
		
	}
	return 0;
}


5043. 鸡尾酒 - AcWing题库

//直接二分
#include<bits/stdc++.h> 
using namespace std;
typedef long long LL;
const int INF = 2e3 + 10;
const int MOD = 1e9 + 7;
const double res = 1e-8;
double a[30],b[30];
int n,v;
bool check(double x)
{
	double sum = 0;
	for(int i = 1;i <= n;i ++)
	{
		sum += a[i] * x;
		if(a[i] * x > b[i])
		{
			return false;
		}
	}
	if(sum > v)return false;
	return true;
}

int main()
{
	cin>>n>>v;
	for(int i = 1;i <= n;i ++)
	{
		cin>>a[i];
	}
	for(int i = 1;i <= n;i ++)
	{
		cin>>b[i];
	}
	double l = 0, r = v * 1.0 / n;
	while(r - l > res)
	{
		double mid = (l + r) / 2;
		if(!check(mid))
		{
			r = mid;
		}
		else l = mid;
	}
	double ans = 0;
	for(int i = 1;i <=n;i ++)
	{
		ans += r * a[i];
	}
	printf("%lf\n",ans);
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值