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;
}