当前位置:网站首页>codeforces 1647A Madoka and Math Dad
codeforces 1647A Madoka and Math Dad
2022-07-21 05:04:00 【这一wa是晚安】
Madoka finally found the administrator password for her computer. Her father is a well-known popularizer of mathematics, so the password is the answer to the following problem.
Find the maximum decimal number without zeroes and with no equal digits in a row, such that the sum of its digits is nn.
Madoka is too tired of math to solve it herself, so help her to solve this problem!
Input
Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Description of the test cases follows.
The only line of each test case contains an integer nn (1≤n≤10001≤n≤1000) — the required sum of the digits.
Output
For each test case print the maximum number you can obtain.
Example
input
Copy
5 1 2 3 4 5output
Copy
1 2 21 121 212
题意:
给你一个数字n,请找出一个十进制的数,十进制的各位数之和等于n,该十进制数不能有零出现,同时相邻两个数之间不能有重复,并且尽可能让这个十进制的数大,你的输出是最大的那个值。
例如 3
它的组合有 111, 21, 12。111有相邻重复出现的情况不符合题意,21>12,所以你最终的答案是21。
题解:
因为题目要求我们的数字尽可能的大,而且不能有连续重复的数字,所以我们让我们的答案尽可能的位数变多就可以了(而不是让每一位最大比如9,一个9我们可以3组(2,1)位数就多了五位显然最后的答案更大了),那么最关键的就是我们怎样使我们的答案位数最长且没有重复呢?那么我们就可以采取让1,2这两个数字重复出现,来符合我们得要求
接下来就是让谁来第一个出现的问题了,因为我们相当于将n能分成多少个3然后余下几的问题,并且我们要让我们的数最大,肯定是让2优先出现最好了,但是你如果是2 1组合的话你最后如果余下的那个数是1,你最后一个出现的数字一定是1,那么最后就是(1,1)不满足题意,如果余数是2或者0,那么2 1组合将没有问题,所以当n%3 = 1, 我们就是1 2 组合就是了。
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, m, t;
int arr[N];
void solve()
{
int s;
cin >> n;
if(n % 3 == 1) s = 1;
else
s = 2;
while(n){
cout << s;
n -= s;
s -= 3;
s = abs(s);
}
cout << endl;
}
int main()
{
IOS;
cin >> t;
while(t--)
solve();
return 0;
}
边栏推荐
- 【PCB】Altium Designer 中(Via过孔)(文本string)(走线Linear Dimension)等项目修改默认设置
- As7341 spectrum sensor measures color temperature color_ temperature_ Study notes
- 学习IO由浅入深
- 栈,队列,链表
- 1. Learn the environment installation and basic calculation of paddlepaddle from scratch
- 3. Build the basic model of paddlepaddle from scratch (compare with keras and pytorch)
- Mask RCNN loading weight error
- 合泰HT32 & 淘晶驰TJC--T0串口屏学习笔记
- FTP cannot create multi-level directories [circular creation problem]
- 以独占的方式锁定此配置文件失败。另一个正在运行的VMware进程可能正在使用配置文件。
猜你喜欢
Database connection failed
分布式事务其中的那些坑
基于OpenCV和Dlib+fr的人脸检测以及基于Dlib人脸对齐
枚举的例子
简单认清深拷贝和浅拷贝
[record] the operation of optisystem is stuck, and it is unable to click to close, input variable values and other solutions
pytorch的安装
数据库连接不上
[PCB] Based on Hetai ht32f52352 chip circuit board drawing experiment (WiFi and optical sensor module) - drawing board notes
Data consistency of Nacos registry cluster
随机推荐
(环境配置)TDD-net
Bucket sort, bubble sort, quick sort
基于STM32F407的摄像头(不带FIFO的OV7670)图像采集及LCD显示实验-笔记整理
Data consistency of Nacos registry cluster
4. 10 lines of code MNIST handwritten numeral recognition of paddlepaddle
Isempty and isblank
【C语言】一些常用的字符串函数--学习笔记
栈,队列,链表
以独占的方式锁定此配置文件失败。另一个正在运行的VMware进程可能正在使用配置文件。
Account类
CONDA install datasets to avoid conflicting commands
mac brew install mysql 安装步骤
Original code, inverse code, complement and logical operation "and or not"
FTP cannot create multi-level directories [circular creation problem]
【PCB】Altium Designer 中(Via过孔)(文本string)(走线Linear Dimension)等项目修改默认设置
回型输入和回型输出
[404] the server starts successfully, and the default page cannot be accessed
OPT101单片光电二极管和单电源互阻放大器使用说明
Bert原理概述
UNET reproduction and environment configuration (including dataset)