当前位置:网站首页>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;
边栏推荐
- [opencv learning] [template matching]
- Unity skframework framework (XVI), package manager development kit Manager
- Jerry's weather direction coding table [chapter]
- Jerry's watch ringtone audition [article]
- 机器学习基础(二)——训练集和测试集的划分
- 2022 Heilongjiang provincial examination on the writing skills of Application Essays
- 日本赌国运:Web3.0 ,反正也不是第一次失败了!
- 【云原生数据库】遇到慢SQL该怎么办(上)?
- 操作教程:EasyDSS如何将MP4点播文件转化成RTSP视频流?
- Independent and controllable 3D cloud CAD: crowncad enables innovative design of enterprises
猜你喜欢

2、 Frame mode MPLS operation

Unity skframework framework (XIII), question module

Performance optimization of memory function

(7) Web security | penetration testing | how does network security determine whether CND exists, and how to bypass CND to find the real IP

运维必备——ELK日志分析系统

2022 Heilongjiang provincial examination on the writing skills of Application Essays

国内首款、完全自主、基于云架构的三维CAD平台——CrownCAD(皇冠CAD)

Redis数据库持久化

Unity SKFramework框架(十五)、Singleton 单例

题解《子数整数》、《欢乐地跳》、《开灯》
随机推荐
Daily question: 1175 Prime permutation
Unity SKFramework框架(十三)、Question 问题模块
Nohup command
Web基础
Unity skframework framework (XVI), package manager development kit Manager
leetcode621. task scheduler
量子三体问题: Landau Fall
Unity SKFramework框架(十六)、Package Manager 開發工具包管理器
Node.js通过ODBC访问PostgreSQL数据库
Unity skframework framework (XIII), question module
Unity SKFramework框架(二十一)、Texture Filter 贴图资源筛选工具
Bridge of undirected graph
Unity skframework framework (XIV), extension extension function
D为何链接不了dll
Post order traversal sequence of 24 binary search tree of sword finger offer
Embedded software development
de4000h存储安装配置
Principle analysis of security rememberme
How to get the operating system running PHP- How to get the OS on which PHP is running?
Pocket Raider comments