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