CodeForce #592(div2)A~C

A题
A题——Pens and Pencils
这个题写的是比较快的,但是问题是在下的英文实在是不咋样,所以我读题本身就慢好多。但是努力学习就好了。

这个题目当时看完给我感觉就是暴力,注意一点就是
eg:三场讲座一根pen刚好,但是四场就不够了,但是第二根pen用不完,我们这里是进一不四舍五入。我们需要2个pen。

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b,c,d,k;
		cin>>a>>b>>c>>d>>k;
		int sum1,sum2;
		sum1=(a-1)/c+1;
		sum2=(b-1)/d+1;
		if(sum1+sum2>k)
			cout<<"-1"<<endl;
		else
			cout<<sum1<<" "<<sum2<<endl;
	} 
	return 0;
 } 

B题

B题——Rooms and Staircases

思路:
如果没有梯子,那么我们最多只能将一行完全走完,最多的结果为n
但是一旦有了梯子(假设在第k间房子),也就是说我们能形成一二层之间的通道,假设我们是从二楼左边开始出发,遇到梯子就下来,让后在一楼继续朝左侧行驶,也就是说从左侧开始到左侧结束。我们会有两结果,一个梯子左边,2*(k)个房间。另外一个是2*(n-k+1)个房间。最终只需要比较大小输出即可。

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		int k;
		cin>>n;
		string s;
		cin>>s;
		k=s.find('1');
		int r=s.rfind('1');
		if(k==-1)
			cout<<n<<endl;
		else
			cout<<max(r+1,n-k)*2<<endl; 	
	}
	return 0;	
}

C题

C题——The Football Season

注意一点:
输入数据w>d;
因为d<w,那么可以知道y<w,因为当y≥w时,w个d不如x=d时,d个w划算。
然后w的范围也比较小,所以直接枚举判断就是了。

#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
int main ()
{
	cin.tie(nullptr);
	cout.tie(nullptr);
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
 
	ll n, p, w, d;
	cin >> n >> p >> w >> d;
 
	for (ll y = 0; y <= w; y++) {
		ll sum = p - y*d;
		if (sum < 0)
			continue;
		if (sum % w == 0) {
			ll x = sum / w;
			ll z = n-x-y;
			if (z >= 0) {
				cout << x << ' ' << y << ' ' << z;
				return 0;
			}
		}
	}
 
	cout << -1;
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值