Educational Codeforces Round 50 (Rated for Div. 2)

http://codeforces.com/contest/1036

B: 题意简单,就不说了




#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;
typedef long long LL;

const int maxn=1e5+20;
const int mod = 1e9 + 7;


int main()
{
	int t;
	cin >> t;

	LL n,m,k;
	while (t--)
	{
		cin >> n >> m >> k;
		if (m < n)
			swap(n, m);
		LL ans = 0;
		ans = n;
		m -= n;
		k -= n;

		if (m > k ) {
			cout << -1 << endl;
			continue;
		}
		ans += m / 2*2;
		k -= m;
		m = m % 2;

		ans += k / 4*4;
		k = k % 4;
		if (k > 0)
		{
			if (m)
			{
				ans += k;
			}
			else
			{
				if (k == 1)
					ans--;
				else if (k == 2)
					ans += 2;
				else if (k == 3)
					ans++;
			}
		}

		cout << ans << endl;

	}



	return 0;
}

看了别人代码两三行解决..............打扰了

 

 

C:求范围内,满足非0位数小于等于3的数有几个

 

这是打表的做法,先筛出1e18里所有满足的数,然后每次询问都二分查找。

本来是用数位dp的,但是真心不好写......


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
typedef long long LL;

const int maxn=1e5+20;
const int mod = 1e9 + 7;


vector <LL> vec;


void dfs(int cnt,int pos,LL val)
{
	if (cnt > 3)
		return;
	vec.push_back(val);
	if (pos == 19)
		return;
	for (int i = 0; i <= 9; i++)
	{
		dfs(cnt + (i ? 1 : 0), pos + 1, val * 10 + i);
	}
}


int main()
{
	int t;
	cin >> t;
	for (int i = 1; i <= 9; i++)
		dfs(1, 1, i);
	sort(vec.begin(), vec.end());
	while (t--)
	{
		LL l, r;
		cin >> l >> r;
		LL a = lower_bound(vec.begin(), vec.end(), l)-vec.begin();
		LL b = upper_bound(vec.begin(), vec.end(), r) - vec.begin();
		cout << b - a << endl;

	}




	return 0;
}

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值