当前位置:网站首页>Solve "sub number integer", "jump happily", "turn on the light"
Solve "sub number integer", "jump happily", "turn on the light"
2022-07-02 13:29:00 【Pandaoxi】
List of articles

A whole number of children
Title Description
For a five digit number a 1 a 2 a 3 a 4 a 5 a_1a_2a_3a_4a_5 a1a2a3a4a5, It can be divided into three subnumbers :
s u b 1 = a 1 a 2 a 3 sub_1=a_1a_2a_3 sub1=a1a2a3
s u b 2 = a 2 a 3 a 4 sub_2=a_2a_3a_4 sub2=a2a3a4
s u b 3 = a 3 a 4 a 5 sub_3=a_3a_4a_5 sub3=a3a4a5
for example , Five figures 20207 20207 20207 Can be broken down into
s u b 1 = 202 sub_1=202 sub1=202
s u b 2 = 020 ( = 20 ) sub_2=020(=20) sub2=020(=20)
s u b 3 = 207 sub_3=207 sub3=207
Now let's give a positive integer K K K, Ask you to program out 10000 10000 10000 To 30000 30000 30000 All five digits that meet the following conditions , The condition is that three of these five digits s u b 1 , s u b 2 , s u b 3 sub_1,sub_2,sub_3 sub1,sub2,sub3 Can be K K K to be divisible by .
Input format
A positive integer K
Output format
A five digit number for each action , Require output from small to large . Do not repeat output or omit . If there is no solution , The output “No”.
Examples #1
The sample input #1
15
Sample output #1
22555
25555
28555
30000
Tips
0 < K < 1000 0<K<1000 0<K<1000
Answer key
// Author:PanDaoxi
#include <iostream>
using namespace std;
bool f(char s[],int k){
// Write a function to judge whether it can be divided after cutting
int sub[4]={
};
sub[0]=(s[0]-'0')*100+(s[1]-'0')*10+(s[2]-'0'),
sub[1]=(s[1]-'0')*100+(s[2]-'0')*10+(s[3]-'0'),
sub[2]=(s[2]-'0')*100+(s[3]-'0')*10+(s[4]-'0');
// cout<<sub[0]<<" "<<sub[1]<<" "<<sub[2]<<endl;
// Return results
return (sub[0]%k==0&&sub[1]%k==0&&sub[2]%k==0)?true:false;
}
int main(){
int k,a[30001],n=0;
cin>>k;
for(int i=10000;i<=30000;i++){
// It was written incorrectly , But I'm too lazy to change , Direct conversion string nested function
char s[7]={
};
s[0]=i/10000+'0',
s[1]=(i%10000)/1000+'0';
s[2]=(i%1000)/100+'0';
s[3]=(i%100)/10+'0';
s[4]=i%10+'0';
if(f(s,k)) a[n++]=i; // Stored in the array
}
if(n==0){
// unsolvable
cout<<"No";
return 0;
}
for(int i=0;i<n;i++){
cout<<a[i]<<endl;
}
return 0;
}
Happy jump
Title Description
One n n n An integer array of elements , If the absolute value of the difference between two consecutive elements of the array includes [ 1 , n − 1 ] [1,n-1] [1,n−1] Between all the integers , It is called consistent with “ Happy jump ”, Such as arrays 1423 1 4 2 3 1423 accord with “ Happy jump ”, Because the absolute values of the difference are : 3 , 2 , 1 3,2,1 3,2,1.
Given an array , Your task is to determine whether the array matches “ Happy jump ”.
Input format
The first row of each set of test data is represented by an integer n ( 1 ≤ n ≤ 1000 ) n(1 \le n \le 1000) n(1≤n≤1000) Start , Next n n n A space separated in [ − 1 0 8 -10^8 −108, 1 0 8 10^8 108] Integer between .
Output format
For each group of test data , Output a line if the array matches “ Happy jump ” The output "Jolly", Otherwise output "Not jolly".
Examples #1
The sample input #1
4 1 4 2 3
Sample output #1
Jolly
Examples #2
The sample input #2
5 1 4 2 -1 6
Sample output #2
Not jolly
Tips
1 ≤ n ≤ 1000 1 \le n \le 1000 1≤n≤1000
Answer key
// Author:PanDaoxi
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n,a[1001];
bool flag=false;
cin>>n;
// Read in the data
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n-1;i++){
// According to the meaning of the title , Write the formula
int t=abs(a[i]-a[i+1]);
if(1<=t&&t<=n) flag=true;
else flag=false; // Do not conform to the
}
if(flag==true) cout<<"Jolly";
else cout<<"not Jolly";
return 0;
}
turn on the light
Title Description
On an infinitely long road , There is an endless line of street lights , The number is 1 , 2 , 3 , 4 , … 1,2,3,4,… 1,2,3,4,….
There are only two possible states for each lamp , On or off . If you press the switch of a lamp , Then the state of this lamp will change . If it turns out to be on , It's going to turn off . If it turns out to be off , It's going to turn on .
At the beginning , All the lights are off . Xiaoming can perform the following operations every time :
Specify two numbers , a , t a,t a,t( a a a It's a real number , t t t As a positive integer ). Will be numbered as [ a ] , [ 2 × a ] , [ 3 × a ] , … , [ t × a ] [a],[2 \times a],[3 \times a],…,[t \times a] [a],[2×a],[3×a],…,[t×a] Once for each of the lights . among [ k ] [k] [k] For real numbers k k k The integral part of .
In Xiaoming n n n After the first operation , Xiaoming suddenly finds out , Only one light is on at this time , Xiao Ming would like to know the number of this lamp , But this lamp is too far away from Xiaoming , Xiao Ming can't see the number .
fortunately , Xiaoming still remembers the previous n n n operations . So Xiaoming finds you , Can you help him figure out the number of the light on ?
Input format
First line a positive integer n n n, Express n n n operations .
Next there is n n n That's ok , Two numbers per line , a i , t i a_i,t_i ai,ti. among a i a_i ai Is the set of real Numbers , There must be... After the decimal point 6 6 6 position , t i t_i ti It's a positive integer. .
Output format
Just a positive integer , The number of the light on .
Examples #1
The sample input #1
3
1.618034 13
2.618034 7
1.000000 21
Sample output #1
20
Tips
remember T = t 1 + t 2 + t 3 + … + t n T=t_1+t_2+t_3+…+t_n T=t1+t2+t3+…+tn.
about 30 % 30\% 30% The data of , Satisfy T ≤ 1000 T \le 1000 T≤1000
about 80 % 80\% 80% The data of , Satisfy T ≤ 200000 T \le 200000 T≤200000
about 100 % 100\% 100% The data of , Satisfy T ≤ 2000000 T \le 2000000 T≤2000000
about 100 % 100\% 100% The data of , Satisfy n ≤ 5000 , 1 ≤ a i < 1000 , 1 ≤ t i ≤ T n \le 5000,1 \le a_i<1000,1 \le t_i \le T n≤5000,1≤ai<1000,1≤ti≤T
Data assurance , after n n n After the first operation , There is and only one lamp is on , There's no need to make a mistake . And for all the i i i Come on , t i × a i t_i\times a_i ti×ai The maximum value of is not more than 2000000.
Answer key
// Author:PanDaoxi
#include <iostream>
using namespace std;
int main(){
int n;
// Write a Boolean array to store data , And less space is used
bool flag[20000001]={
};
cin>>n;
for(int i=1;i<=n;i++){
// Enter a real number a and Integers t
double a;
int t;
cin>>a>>t;
// Core processing , Turn off the street lights and turn them on , Turn it on turn it off
for(int j=1;j<=t;j++){
// A mathematical principle
flag[int(j*a)]-=1;
flag[int(j*a)]*=-1;
}
}
// Output results
for(int i=1;i<20000001;i++){
if(flag[i]){
cout<<i;
return 0;
}
}
return 0;
}
The mathematical principles mentioned above , I mean, put 1 become 0, hold 0 And then become 1 This matter . If you write directly if It will time out .
I first thought of using absolute value , Look, here is a 0, It decreases 1 Just change -1 了 ,-1 The absolute value of is 1;1 subtract 1 become 0,0 The absolute value of is still 0. So it changed .
Further simplification , Because subtract 1 In the future, non positive numbers , therefore , The absolute value of a negative number is its opposite , We can express it as -1 The opposite number of is 1, And it stipulates 0 The opposite number of is 0. therefore , We have :
x-=1;
// x=-x;
x*=-1;
边栏推荐
- Unity SKFramework框架(二十)、VFX Lab 特效库
- Web Foundation
- Unity SKFramework框架(十六)、Package Manager 開發工具包管理器
- 三翼鸟两周年:羽翼渐丰,腾飞指日可待
- 能自动更新的万能周报模板,有手就会用!
- Unity skframework framework (XXI), texture filter map resource filtering tool
- Unity SKFramework框架(十二)、Score 计分模块
- 题解《子数整数》、《欢乐地跳》、《开灯》
- 2022零代码/低代码开发白皮书【伙伴云出品】附下载
- Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk
猜你喜欢
![Jerry's watch delete alarm clock [chapter]](/img/7f/d51b37872b4ce905a0a723a514b2dc.jpg)
Jerry's watch delete alarm clock [chapter]

net share

mac(macos Monterey12.2 m1) 个人使用php开发

Can automatically update the universal weekly report template, you can use it with your hand!

Unity SKFramework框架(十四)、Extension 扩展函数

Unity SKFramework框架(十三)、Question 问题模块
![[true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials](/img/42/21f6d0fdd159faa8b63713624c95a2.png)
[true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials

Ali on three sides, it's really difficult to successfully get the offer rated P7
![[opencv learning] [contour detection]](/img/96/aaec61f137e4526c2c329e6fcfa1a2.jpg)
[opencv learning] [contour detection]

操作教程:EasyDSS如何将MP4点播文件转化成RTSP视频流?
随机推荐
TVOC, VOC, VOCs gas detection + Solution
Ali was killed by two programming problems at the beginning, pushed inward again, and finally landed (he has taken an electronic offer)
PR usage skills, how to use PR to watermark?
三谈exception——错误处理
Node. JS accessing PostgreSQL database through ODBC
[opencv learning] [image filtering]
Research shows that "congenial" is more likely to become friends
Unity skframework framework (XXI), texture filter map resource filtering tool
Finally, someone explained the supervised learning clearly
Unity skframework framework (XX), VFX lab special effects library
Should I have a separate interface assembly- Should I have a separate assembly for interfaces?
Unity skframework framework (XV), singleton singleton
Three methods of finding LCA of the nearest common ancestor
验证失败,请检查您的回电网址。您可以按照指导进行操作
Unity skframework Framework (XVI), package manager Development Kit Manager
Nohup command
Bridge of undirected graph
Jerry's watch ringtone audition [article]
Principle analysis of security rememberme
How to modify the error of easydss on demand service sharing time?