目录
4861. 构造数列
问题描述:
实现代码:
4862. 浇花
问题描述:
实现代码:
4861. 构造数列
问题描述:
我们规定如果一个正整数满足除最高位外其它所有数位均为 00,则称该正整数为圆数。
例如,1,8,900,70,50001,8,900,70,5000 都是圆数,120,404,333,8008120,404,333,8008 都不是圆数。
给定一个正整数 n,请你构造一个圆数数列,要求:
- 数列中所有元素相加之和恰好为 n。
- 数列长度尽可能短。


实现代码:
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		string nums;
		cin >> nums;
		int count = 0;
		vector<string> result;
		for (int i = 0; i < nums.size(); i++)
		{
			
 			if (nums[i] != '0')
			{
				count++;
				string s = "";
				s += nums[i];
				s += string(nums.size() - i - 1, '0');
				result.push_back(s);
			}
		}
		cout << count << endl;
		for (auto r : result)
		{
			cout << r << " ";
		}
		cout << endl;
	}
}4862. 浇花
问题描述:
某公司养有观赏花,这些花十分娇贵,每天都需要且仅需要浇水一次。
如果某一天没给花浇水或者给花浇水超过一次,花就会在那一天死亡。
公司即将迎来 n 天假期,编号 1∼n1。
为了让花能够活过整个假期,公司领导安排了 m 个人(编号 1∼m)来公司浇花,其中第 i 个人在第 [ai,bi]天每天来公司浇一次花。
领导是按照时间顺序安排的浇花任务,保证了对于 1≤i≤m−1,均满足:bi≤ai+1。
给定领导的具体安排,请你判断,花能否活过整个假期,如果不能,请你输出它是在第几天死的,以及那一天的具体浇水次数。

 

实现代码:
#include<bits/stdc++.h>
using namespace std;
int n;
int m;
int day[100010] = { 0 };
int main()
{
	cin >> n;
	cin >> m;
	for (int i = 1; i <= m; i++)
	{
		int a;
		int b;
		cin >> a;
		cin >> b;
		day[a] += 1;
		day[b + 1] += -1;
	}
	for (int i = 1; i <= n; i++)
	{
		day[i] = day[i] + day[i - 1];
		if (day[i] > 1)
		{
			cout << i <<" "<< day[i] << endl;
			return 0;
			
		}
		if(day[i] == 0)
		{
		    cout << i <<" " <<day[i] <<endl;
		    return 0;
		}
		
	}
	cout << "OK" << endl;
}


















