#723 (Div. 2) B 规律 C1 反悔贪心

B. I Hate 1111
思路1:可以打表前5000个数 可以猜测1099是最后一个无法表示的数,那么前1100个直接暴力判断,后边的输出YES,可以发现ac了~
思路2:
分析每个全1的数
111=11∗10+1,多出来了1,很麻烦,接着搞
1111=11∗100+11,可以
11111=11∗1000+11∗10+1,又多出来了1?那岂不是可以转化?于是转化为111 ∗ 100 + 11 111 * 100 + 11111∗100+11
111111=11∗10000+11∗100+11
1111111=111∗10000+11∗100+11
可以发现问题就是求解 11∗a+111∗b=X 有没有解

C1. Potions (Easy Version)
反悔贪心

#include<bits/stdc++.h>
using namespace std;
priority_queue <int> q;
int n, x;
int main()
{
	cin >> n;
	long long sum = 0, ans = 0;
	for(int i = 1; i <= n; ++i)
	{
		cin >> x;
		if(x >= 0) sum += x, ++ans;
		else 
		{
			if(sum + x >= 0)
				q.push(-x), sum += x, ++ans;
			else 
			{
				if(!q.empty() && q.top() >= (-x))
				{
					sum += q.top();
					q.pop();
					sum += x;
					q.push(-x);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int i,j,k,n,m,t,res;
ll tmp;
priority_queue<int> q;
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d",&k);
		tmp+=k;
		res++;
		q.push(-k);
		while(tmp<0){
			res--;
			tmp+=q.top();q.pop();
		}
	}
	printf("%d",res);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值