牛客周赛67
c
因为c的数据比较小,所以只需要通过便利c,然后计算出加号左右两边的数字,因为题目给的n的意思其实是加号左右两边的数字位数确定了,所以只要保证得出的两边的数字位数满足条件就好
(写的时候吧c的数据大小看成10的n次方了。。。硬是用数学公式算了一小时)
点击查看代码
/* 台州第一深情 */
#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 20;
using ll = long long;
int main()
{
std::ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, c, s = 0;
cin >> n >> c;
for (int a = 0; a <= c; a++)
{
int b = c - a;
string s = to_string(a);
string ss = to_string(b);
string sss = to_string(c);
if (ss.size() + s.size() + sss.size() == n - 2)
{
s++;
}
}
cout << s;
return 0;
}
点击查看代码
/* 台州第一深情 */
#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 20;
using ll = long long;
int a[N];
int n, k;
signed main()
{
cin >> n >> k;
if (k > n)
{
cout << "NO";
return 0;
}
if (k == n)
{
cout << "YES" << "\n";
for (int i = 1; i <= n; i++)
cout << a[i] << " ";
return 0;
}
if (k % 2)
{
a[1] = 1;
k--;
}
int pos = 3;
while (k)
{
a[pos] = 1;
pos += 2;
k -= 2;
}
cout << "YES" << endl;
for (int i = 1; i <= n; i++)
cout << a[i] << " ";
return 0;
}
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 3e5 + 5, M = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
int l, r, L, R;
void solve()
{
cin >> l >> r >> L >> R;
int low = l + L, high = r + R;
vector<int> a, b;
while (low || high)
{
a.push_back(low % 10);
b.push_back(high % 10);
low /= 10, high /= 10;
}
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int n = a.size();
bool ok = false;
int ans = 0, res = 0;
for (int i = 0; i < n; i++)
{
if (a[i] < b[i])
{
ans = max({ans, res + b[i] - 1 + (n - i - 1) * 9, res + b[i]});
}
else
{
ans = max(ans, res + b[i]);
}
res += b[i];
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++)
{
solve();
}
return 0;
}